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());
|
||||
if (defaultValue != null) {
|
||||
defaultValue = defaultValue.replace("\\", "\\\\")
|
||||
.replace("'", "\'");
|
||||
.replace("'", "\\'");
|
||||
if (Pattern.compile("\r\n|\r|\n").matcher(defaultValue).find()) {
|
||||
return "'''" + defaultValue + "'''";
|
||||
} else {
|
||||
|
@ -139,7 +139,7 @@ public class PythonClientCodegenTest {
|
||||
StringSchema schema = new StringSchema();
|
||||
schema.setDefault("Text containing 'single' quote");
|
||||
String defaultValue = codegen.toDefaultValue(schema);
|
||||
Assert.assertEquals("'Text containing \'single\' quote'", defaultValue);
|
||||
Assert.assertEquals("'Text containing \\'single\\' quote'", defaultValue);
|
||||
}
|
||||
|
||||
@Test(description = "test backslash default")
|
||||
|
Loading…
x
Reference in New Issue
Block a user