forked from loafle/openapi-generator-original
Fix single quote escaping for python code generator (and its test) (#21021)
Hard to spot, but in Java the strings "'" and "\'" are identical, so the implementation and its test were broken identically.
This commit is contained in:
parent
63afd455f7
commit
7a3ea2872a
@ -214,7 +214,7 @@ public abstract class AbstractPythonCodegen extends DefaultCodegen implements Co
|
|||||||
String defaultValue = String.valueOf(p.getDefault());
|
String defaultValue = String.valueOf(p.getDefault());
|
||||||
if (defaultValue != null) {
|
if (defaultValue != null) {
|
||||||
defaultValue = defaultValue.replace("\\", "\\\\")
|
defaultValue = defaultValue.replace("\\", "\\\\")
|
||||||
.replace("'", "\'");
|
.replace("'", "\\'");
|
||||||
if (Pattern.compile("\r\n|\r|\n").matcher(defaultValue).find()) {
|
if (Pattern.compile("\r\n|\r|\n").matcher(defaultValue).find()) {
|
||||||
return "'''" + defaultValue + "'''";
|
return "'''" + defaultValue + "'''";
|
||||||
} else {
|
} else {
|
||||||
|
@ -139,7 +139,7 @@ public class PythonClientCodegenTest {
|
|||||||
StringSchema schema = new StringSchema();
|
StringSchema schema = new StringSchema();
|
||||||
schema.setDefault("Text containing 'single' quote");
|
schema.setDefault("Text containing 'single' quote");
|
||||||
String defaultValue = codegen.toDefaultValue(schema);
|
String defaultValue = codegen.toDefaultValue(schema);
|
||||||
Assert.assertEquals("'Text containing \'single\' quote'", defaultValue);
|
Assert.assertEquals("'Text containing \\'single\\' quote'", defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(description = "test backslash default")
|
@Test(description = "test backslash default")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user