Sanitize pipe in var name (#461)

This commit is contained in:
Jérémie Bresson 2018-07-05 06:26:46 +02:00 committed by William Cheng
parent b0cae23777
commit 1d69566cb1
2 changed files with 4 additions and 0 deletions

View File

@ -3631,6 +3631,9 @@ public class DefaultCodegen implements CodegenConfig {
// input-name => input_name // input-name => input_name
name = name.replaceAll("-", "_"); name = name.replaceAll("-", "_");
// a|b => a_b
name = name.replace("|", "_");
// input name and age => input_name_and_age // input name and age => input_name_and_age
name = name.replaceAll(" ", "_"); name = name.replaceAll(" ", "_");

View File

@ -73,6 +73,7 @@ public class AbstractJavaCodegenTest {
Assert.assertEquals(fakeJavaCodegen.toVarName("nam$$e"), "nam$$e"); Assert.assertEquals(fakeJavaCodegen.toVarName("nam$$e"), "nam$$e");
Assert.assertEquals(fakeJavaCodegen.toVarName("user-name"), "userName"); Assert.assertEquals(fakeJavaCodegen.toVarName("user-name"), "userName");
Assert.assertEquals(fakeJavaCodegen.toVarName("user_name"), "userName"); Assert.assertEquals(fakeJavaCodegen.toVarName("user_name"), "userName");
Assert.assertEquals(fakeJavaCodegen.toVarName("user|name"), "userName");
} }
@Test @Test