-
Notifications
You must be signed in to change notification settings - Fork 865
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
Clarify whether keys can contain a newline #826
Comments
The spec says:
So to me that says anything that's legal in a string is legal in a quoted key since they're equivalent, thus this should be legal: "a\nb" = 1 Physical newlines would be illegal of course, just as they would be in a non-key string, though it's worth noting that the spec doesn't explicitly draw attention to the (non-)validity of their multi-line variants. The ABNF appears to prohibit them being used as keys (by omission), though this is likely an oversight; I can't see any reason to prohibit a multi-line string here so long as it didn't contain actual physical newlines.
Why should that be an error? Surely the desired behaviour is to re-emit the key as quoted key with a newline escape code, to exactly round-trip the input (i.e. |
So, to summarize: yes, quoted keys can contain logical newlines, but physically, in the file, these newlines must be escaped, just like in any other non-multiline string. |
Cool, I'll open bug against the library which is emitting actual newlines instead of the escape sequence. Thanks! |
But isn't the behavior of the other library wrong as well? It should treat "\n" as a literal and hence serialize it as |
You're right. I made a mistake, though. I mixed the actual string being output and the language's representation of the string in my initial test for the second library. So when I looked at it again, the second library was doing what is suggested here. |
The text of the spec and the grammar for toml keys is ambiguous with regard to newlines in a key. The spec says:
However, the grammar seems to allow a newline inside of a quoted key:
I've found two libraries which emit
{"a\nb": 1}
differently; either asor
and trying to figure out which one (or both!) I should file a bug on. I'm thinking both of them might be wrong. The first one because newlines are not allowed in keys and the second one because it decodes the toml key
"a\\nb"
as"a\nb"
instead of"a\\nb"
(both libraries should, instead, throw an error when they try to emit a key with a newline in it).Let me know what the spec and grammar really means so I can open the appropriate bugs.
The text was updated successfully, but these errors were encountered: