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

Infinite loop when attempting to parse multi-line scalar document that is not indented (sample included) #144

Closed
cspotcode opened this issue Sep 1, 2014 · 3 comments
Labels

Comments

@cspotcode
Copy link

When attempting to parse the following YAML, the parser gets into an infinite loop, neither successfully parsing nor throwing an error.

--- |
hi

I am not sure which is correct according to the YAML spec: is this an invalid YAML document? Or should it parse to the string "hi"?

@puzrin
Copy link
Member

puzrin commented Sep 1, 2014

What version do you use? We fixed similar bug last week

@cspotcode
Copy link
Author

I'm using the latest version, 3.2.1. It also occurs in the online demo at http://nodeca.github.io/js-yaml/

I noticed that your code is checking if the next character in the stream is !== 0 in many places, as a sort of "end-of-stream" marker.
https://github.com/nodeca/js-yaml/blob/master/lib/js-yaml/loader.js#L856

The original PyYAML code explicitly appends this null character to the end of the input text before parsing.
http://pyyaml.org/browser/pyyaml/trunk/lib/yaml/reader.py#L75

Perhaps that's the problem? In JS when you str.charCodeAt(str.length) you get NaN, not 0.

EDIT: Nevermind, I now see where you're appending the null character in js-yaml.

@dervus dervus added bug labels Sep 3, 2014
@puzrin puzrin mentioned this issue Sep 5, 2014
dervus added a commit that referenced this issue Sep 5, 2014
@dervus dervus removed the in-progress label Sep 5, 2014
@puzrin
Copy link
Member

puzrin commented Sep 6, 2014

Fixed

@puzrin puzrin closed this as completed Sep 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants