Yaml dict keys with ":" parsed incorrectly #1735

Closed
opened 2013-08-10 17:22:50 +02:00 by marijnh · 6 comments
marijnh commented 2013-08-10 17:22:50 +02:00 (Migrated from gitlab.com)

Escaping of dict key don't work

Parsing stops at first found :

Escaping of dict key [don't work](http://yaml-online-parser.appspot.com/?yaml=%22ga%3Asource%22%3A+123&type=json) Parsing stops at first found `:`
marijnh commented 2013-08-12 11:42:42 +02:00 (Migrated from gitlab.com)

Could you point me at the documentation that describes the expected behavior here? (I can't reach the person who actually wrote the Yaml mode, and I've never used Yaml in my life.)

Could you point me at the documentation that describes the expected behavior here? (I can't reach the person who actually wrote the Yaml mode, and I've never used Yaml in my life.)
marijnh commented 2013-08-12 13:30:49 +02:00 (Migrated from gitlab.com)

Here is official gude to basic "Mappings" markup ways.

It says that Mapping key even not have to be escaped, just inserting space after it

Mappings use a colon and space (“: ”) to mark each key: value pair.

So even this example should be valid.

Also mappings have JSON-like "flow" format, but have no clarifications about space-folowed keys.
This example will raise parse error if we remove quotes from key.

Therefore, it can still rely on exact JSON parsing algoritm (where quoting of keys is always required).

[Here](http://yaml.org/spec/1.2/spec.html#id2759963) is official gude to basic "Mappings" markup ways. It says that Mapping key even not have to be escaped, just inserting space after it > Mappings use a colon and space (“: ”) to mark each key: value pair. So even [this example](http://yaml-online-parser.appspot.com/?yaml=ga%3Asource%3A+123&type=json) should be valid. Also mappings have JSON-like ["flow" format](http://yaml.org/spec/1.2/spec.html#id2760372), but have no clarifications about space-folowed keys. [This example](http://yaml-online-parser.appspot.com/?yaml=%7B%22ga%3Asource%22%3A+foobar%7D%0A&type=json) will raise parse error if we remove quotes from key. Therefore, it can still rely on exact JSON parsing algoritm (where quoting of keys is always required).
marijnh commented 2013-08-19 13:37:26 +02:00 (Migrated from gitlab.com)

Could you try with the attached patch?

Could you try with the attached patch?
marijnh commented 2013-08-19 15:58:09 +02:00 (Migrated from gitlab.com)

Just tried, thanks :)

This case

ga:metrics: somevalue
"ga:visits": quotevalue

parsed correctly now 👌

But flow formats behaves differently:

{ga:metrics: value}

is highlights ga:metrics as key. Expected intuitively, but broken on parser example.

If flow-map is sub-item of global document, it's keys became unhighlighted:

ga:visits: {subkey: 123}

subkey is plain text colored in Codemirror, but expected to be colored as key. 😕

Just tried, thanks :) This case ``` yaml ga:metrics: somevalue "ga:visits": quotevalue ``` parsed correctly now :ok_hand: But flow formats behaves differently: ``` yaml {ga:metrics: value} ``` is highlights `ga:metrics` as key. Expected intuitively, but broken on [parser example](http://yaml-online-parser.appspot.com/?yaml=%7Bga%3Ametrics%3A+value%7D&type=json). If flow-map is sub-item of global document, it's keys became unhighlighted: ``` yaml ga:visits: {subkey: 123} ``` `subkey` is plain text colored in Codemirror, but expected to be colored as key. :confused:
marijnh commented 2013-08-19 16:05:36 +02:00 (Migrated from gitlab.com)

Right. The YAML mode was contributed by someone else, and doesn't seem prepared to these kind of subtleties. I am personally not motivated to improve or rewrite it, but such a pull request would be very welcome.

Right. The YAML mode was contributed by someone else, and doesn't seem prepared to these kind of subtleties. I am personally not motivated to improve or rewrite it, but such a pull request would be very welcome.
marijnh commented 2013-08-19 18:50:18 +02:00 (Migrated from gitlab.com)

okay, thanks. Maybe make sense to rewrite this mode or use existing parsing solutions like https://github.com/nodeca/js-yaml package.

BTW, it also uses Codemirror as demo editor engine.

okay, thanks. Maybe make sense to rewrite this mode or use existing parsing solutions like [https://github.com/nodeca/js-yaml](js-YAML) package. BTW, it also uses Codemirror as [demo editor engine](http://nodeca.github.io/js-yaml/).
marijnh (Migrated from gitlab.com) closed this issue 2013-10-17 11:44:06 +02:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
codemirror/codemirror5#1735
No description provided.