Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit fb34d24

Browse files
authored
Merge pull request #178 from skyhit/add_backend_validation_for_project_name_and_description
add backend validation for project name and description
2 parents f883f96 + 58f4469 commit fb34d24

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

services/project_service/src/java/main/com/topcoder/service/project/impl/ProjectServiceBean.java

+19
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.List;
1414
import java.util.Map;
1515
import java.util.Set;
16+
import java.util.regex.Pattern;
1617

1718
import javax.annotation.PostConstruct;
1819
import javax.annotation.Resource;
@@ -371,6 +372,13 @@
371372
@TransactionManagement(TransactionManagementType.CONTAINER)
372373
@TransactionAttribute(TransactionAttributeType.REQUIRED)
373374
public class ProjectServiceBean implements ProjectServiceLocal, ProjectServiceRemote {
375+
/**
376+
* Represents the pattern for project name
377+
*
378+
* @since 2.4
379+
*/
380+
private static final String NAME_PATTERN = "[a-zA-Z0-9\\$\\!\\(\\)\\[\\]'\\\"\\-\\.\\,\\/\\+ ]+";
381+
374382
/**
375383
* Represents the field names to be audit.
376384
*
@@ -1988,6 +1996,17 @@ private void checkProjectData(ProjectData projectData, boolean isCreate) throws
19881996
throw logException(new IllegalArgumentFault("The name attribute of the project data can not be null."));
19891997
} else if (name.trim().length() == 0) {
19901998
throw logException(new IllegalArgumentFault("The name attribute of the project data can not be empty."));
1999+
} else if (!Pattern.matches(NAME_PATTERN, name)) {
2000+
throw logException(new IllegalArgumentFault("The name attribute of the project data is not following pattern as - " + NAME_PATTERN));
2001+
}
2002+
2003+
String description = projectData.getDescription();
2004+
if (null == description) {
2005+
throw logException(new IllegalArgumentFault("The description attribute of the project data can not be null."));
2006+
} else if (description.trim().length() == 0) {
2007+
throw logException(new IllegalArgumentFault("The description attribute of the project data can not be empty."));
2008+
} else if (!Pattern.matches(NAME_PATTERN, description)) {
2009+
throw logException(new IllegalArgumentFault("The description attribute of the project data is not following pattern as - " + NAME_PATTERN));
19912010
}
19922011

19932012
//added in version 2.2

0 commit comments

Comments
 (0)