Skip to content

Commit

Permalink
fix: escape single quotes in strings in generated Python code (#1312)
Browse files Browse the repository at this point in the history
Closes #1310

### Summary of Changes

Single quotes in strings are now escaped in the generated Python code.
  • Loading branch information
lars-reimann authored Jan 18, 2025
1 parent 88295bc commit 938f082
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ export class SafeDsPythonGenerator {
}

private formatStringSingleLine(value: string): string {
return value.replaceAll('\r\n', '\\n').replaceAll('\n', '\\n');
return value.replaceAll('\r\n', '\\n').replaceAll('\n', '\\n').replaceAll("'", "\\'");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ def test():
f(None)
f('')
f('multi\nline')
f('\'')

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ pipeline test {
f("");
f("multi
line");

// https://github.com/Safe-DS/DSL/issues/1310
f("'");
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

def test():
f(f'start\n{ g() }\ninner { g() }\nend')
f('\'')

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ pipeline test {
{ g() }
inner { g() }
end`);

// https://github.com/Safe-DS/DSL/issues/1310
f(`'`);
}

0 comments on commit 938f082

Please sign in to comment.