Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String value is escaped in an unwanted way #14

Open
Schwusch opened this issue Feb 28, 2022 · 2 comments
Open

String value is escaped in an unwanted way #14

Schwusch opened this issue Feb 28, 2022 · 2 comments
Labels
type-enhancement A request for a change that isn't a bug

Comments

@Schwusch
Copy link

Schwusch commented Feb 28, 2022

When updating a string value with forward slashes, the resulting string escapes the forward slashes unnecessarily:

final doc = YamlEditor('exampleKey: \${file(../../bar.yml)}');

doc.update(['exampleKey'], '\${file(../../foo.yml)}');

print(doc);
// exampleKey: ${file(..\/..\/bar.yml)}

My current workaround is to modify the resulting string:

doc.toString().replaceAll('\\/', '/')

It would be nice to customize that behaviour.

@jonasfj jonasfj added the type-enhancement A request for a change that isn't a bug label Mar 17, 2022
@jonasfj
Copy link
Member

jonasfj commented Mar 17, 2022

// exampleKey: ${file(..\/..\/bar.yml)}

Are you sure it's not double quoting it, as:
// exampleKey: "${file(..\/..\/bar.yml)}"


On topic, I'm guessing we could make the strings prettier. Contributions are welcome, but I think it would be best to have:

  • Lots of test cases, and,
  • Source code comments arguing why not escaping certain sequences is always safe.

@Schwusch
Copy link
Author

Are you sure it's not double quoting it, as:
// exampleKey: "${file(../../bar.yml)}"

Oh yeah, that's right. When skipping the { and } characters, everything worked as expected during experimentation, with no double quotes or escaping:

doc.update(['exampleKey'], '\$file(../../foo.yml)');
print(doc);
// exampleKey: $file(../../foo.yml)

So curly braces makes this function return true:

bool isDangerousString(String string) {

and then that triggers escaping all code units in this map:
final Map<int, String> doubleQuoteEscapeChars = {

But the forward slashes, in itself, does not trigger any character escaping.

I can make a PR if there is a consensus on the solution. Personally, I'd like to pass a parameter to skip all checks for dangerous strings and skip all character replacing somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

2 participants