Skip to content

Commit

Permalink
Allow colons in plain scalars inside flow collections
Browse files Browse the repository at this point in the history
This is a followup to yaml#28

See http://yaml.org/spec/1.1/#nb-plain-char(c) and the following
productions.

This commit will allow `[http://example]`, but still fail for:
- `[:foo]`
- `[foo:]`
  • Loading branch information
perlpunk committed Jun 25, 2018
1 parent 83d3d38 commit b2c909e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/scanner.c
Expand Up @@ -3430,11 +3430,22 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token)

while (!IS_BLANKZ(parser->buffer))
{
/* Check for 'x:x' in the flow context. TODO: Fix the test "spec-08-13". */
/* Check for "x:" + one of ',?[]{}' in the flow context. TODO: Fix the test "spec-08-13".
* This is not completely according to the spec
* See http://yaml.org/spec/1.1/#id907281 9.1.3. Plain
*/

if (parser->flow_level
&& CHECK(parser->buffer, ':')
&& !IS_BLANKZ_AT(parser->buffer, 1)) {
&& (
CHECK_AT(parser->buffer, ',', 1)
|| CHECK_AT(parser->buffer, '?', 1)
|| CHECK_AT(parser->buffer, '[', 1)
|| CHECK_AT(parser->buffer, ']', 1)
|| CHECK_AT(parser->buffer, '{', 1)
|| CHECK_AT(parser->buffer, '}', 1)
)
) {
yaml_parser_set_scanner_error(parser, "while scanning a plain scalar",
start_mark, "found unexpected ':'");
goto error;
Expand All @@ -3444,7 +3455,7 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token)

if ((CHECK(parser->buffer, ':') && IS_BLANKZ_AT(parser->buffer, 1))
|| (parser->flow_level &&
(CHECK(parser->buffer, ',') || CHECK(parser->buffer, ':')
(CHECK(parser->buffer, ',')
|| CHECK(parser->buffer, '?') || CHECK(parser->buffer, '[')
|| CHECK(parser->buffer, ']') || CHECK(parser->buffer, '{')
|| CHECK(parser->buffer, '}'))))
Expand Down

0 comments on commit b2c909e

Please sign in to comment.