Erroneous Inclusion of Double Quotes for Parsed Double Quoted Strings
See original GitHub issueI have a YAML file with these(obscured) contents:
hostname: localhost
password: "Password!@#"
port: 61616
username: myuser
and the double quotes around the password make it into the parsed string when calling
this.password = yamlMapping.string("password");
in my code. Therefore, I had to implement a regex-based hack:
this.password = yamlMapping.string("password").replaceAll("^\"|\"$", "");
This is definitely annoying, and I’m almost certain that it’s a bug because I scoured the web looking at pages on YAML for any sign of this behavior in other libraries. I found no evidence that this is the intended behavior / spec.
NB: The double quotes are necessary because the # at the end of the string in the YAML file gets excised since it is the comment character for YAML.
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
What is the difference between single-quoted and double ...
A double-quoted string does. Also, a double-quoted string can contain apostrophes without backslashes, while a single-quoted string can contain unescaped ...
Read more >fixed-strings does not find matches with double-quotation marks
It seems that on Windows, if you want to include double quotes in the cmd line, you must escape it with a backslash...
Read more >about Quoting Rules - PowerShell | Microsoft Learn
A string enclosed in double quotation marks is an expandable string. Variable names preceded by a dollar sign ( $ ) are replaced...
Read more >Quotes - R
Single quotes need to be escaped by backslash in single-quoted strings, and double quotes in double-quoted strings.
Read more >Strings in YAML - To Quote or not to Quote | tinita [blogs.perl.org]
The good news is, the YAML double quoted string works the same as in JSON, so if you know that already, you will...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@aquishix By the way, don’t forget that both
YamlMapping
andYamlSequence
are interfaces, so you can decorate them and put that regex logic there, like this:@aquishix I just had a look as well, on yamllint.com and I think you’re right. I also kind of remember from the specification (it was a rather long time ago) that yaml “escapes” special charaters such as
#
by wrapping the string between double quotes…So yes, maybe there should be some logic to eliminate double quotes if they are present.
I will fix it, but it will take a few days, I don’t have time right now, sorry. If you need a fix urgently, try making a PR (but make sure the architecture of the library is not broken).