Skip to content

Commit

Permalink
Merge pull request #11072 from swagger-api/swos-240
Browse files Browse the repository at this point in the history
removed all non valid characters on project name
  • Loading branch information
HugoMario authored Jun 26, 2021
2 parents ca87148 + 053ebca commit a5627c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ public void processOpts() {
}

if (additionalProperties.containsKey(CodegenConstants.PROJECT_NAME)) {
setProjectName((String) additionalProperties.get(CodegenConstants.PROJECT_NAME));
String projectName = (String) additionalProperties.get(CodegenConstants.PROJECT_NAME);
setProjectName(projectName.replaceAll("[^a-zA-Z0-9\\s\\-_]",""));
}
else {
// default: set project based on package name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,13 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception {
Assert.assertEquals(codegen.isHideGenerationTimestamp(), false);
}

@Test
public void testProjectNameCharacters() {
String projectName = ";import os; -;os.system('ping localhost');x=b;_yy=";
Assert.assertEquals(projectName.replaceAll("[^a-zA-Z0-9\\s\\-_]",""), "import os -ossystemping localhostxb_yy");
Assert.assertEquals("petstore-api".replaceAll("[^a-zA-Z0-9\\s\\-_]",""), "petstore-api");
Assert.assertEquals("petstore_api2".replaceAll("[^a-zA-Z0-9\\s\\-_]",""), "petstore_api2");
Assert.assertEquals("petstore api".replaceAll("[^a-zA-Z0-9\\s\\-_]",""), "petstore api");
}

}

0 comments on commit a5627c0

Please sign in to comment.