question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Erroneous Inclusion of Double Quotes for Parsed Double Quoted Strings

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
amihaiemilcommented, Oct 10, 2018

@aquishix By the way, don’t forget that both YamlMapping and YamlSequence are interfaces, so you can decorate them and put that regex logic there, like this:

public final class Escaped implements YamlMapping {

    private final YamlMapping unescaped;

    ...

    public String string(final String key) {
        String value = this.unescaped.string(key);
        return value.replaceAll("^\"|\"$", "");
    }
 
    ...

}
1reaction
amihaiemilcommented, Oct 10, 2018

@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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found