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
follow up on #470->#473: no quotes when not absolutely necessary #484
Conversation
…ll round trip tests pass. # Conflicts: # test/issues/0470.js
# Conflicts: # test/issues/0470.js
&& !isWhitespace(string.charCodeAt(string.length - 1)); | ||
&& !isWhitespace(string.charCodeAt(string.length - 1)) | ||
&& /\s#/.test(string) === false | ||
&& /:(?:\s|$)/.test(string) === false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All checks should be done via .charCodeAt()
for perfomance reasons.
Also, this lines are not descriptive - difficult to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would comments help (apart from the fact that these are otherwise undesirable, see also my comments further below about the new insights about this)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, comments help in such cases. Or descriptive helper function names (like isWhiteSpace
, hasCommentPattern
)
But regexps should not be used - see any other part of code, there are no regexps.
@@ -296,7 +287,7 @@ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, te | |||
// in case the end is missing a \n | |||
hasFoldableLine = hasFoldableLine || (shouldTrackWidth && | |||
(i - previousLineBreak - 1 > lineWidth && | |||
string[previousLineBreak + 1] !== ' ')); | |||
string[previousLineBreak + 1] !== ' ')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it doesn't worth to change indent here if that's not related to your issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was eslint --fix (make fix
) in action
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=> don't use eslint --fix
:)
There is local make lint
with appropriate config, and it does not report error on this line.
Breaking my own stuff
as that dumps to
and on loading that input, js-yaml barfs a hairball due to the , comma in an unexpected place. |
After reconsidering the YAML spec and everything, I now believe this #470, #473 approach is severely flawed as you either need very context-sensitive checks to prevent it from producing illegal yaml output (under edge conditions, but see the example in the previous comment: you get breakage anyway and that's very much undesirable). Instead, if you want fewer quoted strings in your yaml output (like I do too), we'd better augment the js-yaml dumper code to produce literal style or folded style string values, cf. https://yaml.org/spec/1.2/spec.html#id2760844 "Odd"/"irregular" keys should be quoted; at least I don't mind if those are. In short: this pullreq is to be rejected as it introduces more risk of errors for arbitrary, otherwise legal, yaml inputs and is not the proper way forward as folded style and literal style output is meant for this type of requirement: "no or only few quoted strings wanted in the dumped output". |
Do you mean
Great catch! Probably, it would be nice have such test, to protect from "too aggressive" quotes remove. |
For block scalars. To be precise: https://yaml.org/spec/1.2/spec.html#id2793652 Copy-pasta example 8.1 from the linked spec above (layout errors here may happen; everyone should refer to the linked spec for the real deal):
===>
Another pullreq will be forthcoming this week for dialing up the fuzzy run count from default 100 to 3000: it only takes a few seconds runtime (granted, on my i7 dev box) but that increased number increases the chance everyone running the test rig will stumble across this and similar hard-to-catch failures, as ultimately it was the fuzzy test rig that produced that edge case right there 👍 -- the only trouble being #483, which simply meant the fuzz box only caught onto it every once in a while 😢 . |
Off Topic:I'm looking into the yaml/yaml-test-suite and checking if I can make that one fly for js-yaml: it's loaded with edge cases and nasty stuff that's collected from multiple libs. |
@GerHobbelt regarding https://github.com/yaml/yaml-test-suite Would be cool if you want to start using the test suite. Glad for any questions, comments, improvements =) |
@perlpunk Seen ya (just now 😄); I saw it and was looking for a fast-track quick-and-dirty approach that works for my "messing around with" js-yaml, so I grabbed your /test/*.tml and took it from there in a few iterations. Should mention: beautiful stuff over at yours but lemme not pollute this issue any further and take that to a new one, as this is really a spin-off of this one. |
Please, don't increase fuzzer's runs count in PR. Long tests are very annoying. Such things can be added via optional ENV var, but should not become a problem for other devs. |
This was fixed by db3f529. Please let me know if it broke anything. I think value in |
object
->yaml.dump
->yaml.safeLoad
-> must matchobject
exactly)char
itself, hence not suitable for inclusion in theisPlainSafe
function (or its interface has to change but that's another cost).Post Postum Ponderings 😄
I did this work on a slightly augmented version of js-yaml and ItWorksForMe® 😉 but I still do wonder if there's a YAML spec situation lurking in the shadows that might trip this up after all...
In other words: can anyone come up with test case(s) that break this aggressive reduction of quoted strings?