8000 Handle object lists that start on the same line as the - by bluesmoon · Pull Request #27 · tj/js-yaml · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jun 25, 2020. It is now read-only.

Handle object lists that start on the same line as the - #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Handle object lists that start on the same line as the - #27

wants to merge 2 commits into from

Conversation

bluesmoon
Copy link

yaml.js has trouble parsing files that look like this one: http://ua-parser.googlecode.com/svn/trunk/resources/user_agent_parser.yaml

The problem appears to be sections like this:

  - regex: '^(Opera)/(\d+)\.(\d+) \(Nintendo Wii'
    family_replacement: 'Wii'

This needs to translate into an object with keys regex and family_replacement, with the object inside a list.

The problem is that yaml.js sees a different indent for the two lines and gets confused.

This patch changes the input to look like this:

  -
    regex: '^(Opera)/(\d+)\.(\d+) \(Nintendo Wii'
    family_replacement: 'Wii'

Which yaml.js is much happier with.

We could probably do much more to make the parser more intelligent, but in this case just canonicalizing the input is simpler and may be faster.

@bluesmoon
Copy link
Author

Note that this is also listed as Issue #19

@tj
Copy link
Owner
tj commented Aug 2, 2011

mind adding a test or two? thanks man!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0