summaryrefslogtreecommitdiff
path: root/ext/psych/yaml/scanner.c
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2020-06-23 13:40:15 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-06-23 15:26:29 +0900
commit70a459986988fecf245cf5eb62e7982e790c8260 (patch)
tree3b3025402039f605c9e9295fa64561f908eced19 /ext/psych/yaml/scanner.c
parent666c077691a5521cb82254911f0abb9575cac9a1 (diff)
[ruby/psych] Bump libyaml version to 0.2.5
https://github.com/ruby/psych/commit/39996192cc
Diffstat (limited to 'ext/psych/yaml/scanner.c')
-rw-r--r--ext/psych/yaml/scanner.c64
1 files changed, 42 insertions, 22 deletions
diff --git a/ext/psych/yaml/scanner.c b/ext/psych/yaml/scanner.c
index 204593d910..6acee7d465 100644
--- a/ext/psych/yaml/scanner.c
+++ b/ext/psych/yaml/scanner.c
@@ -38,8 +38,8 @@
* BLOCK-END # Indentation decrease.
* FLOW-SEQUENCE-START # '['
* FLOW-SEQUENCE-END # ']'
- * BLOCK-SEQUENCE-START # '{'
- * BLOCK-SEQUENCE-END # '}'
+ * FLOW-MAPPING-START # '{'
+ * FLOW-MAPPING-END # '}'
* BLOCK-ENTRY # '-'
* FLOW-ENTRY # ','
* KEY # '?' or nothing (simple keys).
@@ -348,6 +348,7 @@
* SCALAR("another value",plain)
* KEY
* SCALAR("a mapping",plain)
+ * VALUE
* BLOCK-MAPPING-START
* KEY
* SCALAR("key 1",plain)
@@ -711,7 +712,7 @@ yaml_parser_scan_tag_handle(yaml_parser_t *parser, int directive,
yaml_mark_t start_mark, yaml_char_t **handle);
static int
-yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive,
+yaml_parser_scan_tag_uri(yaml_parser_t *parser, int uri_char, int directive,
yaml_char_t *head, yaml_mark_t start_mark, yaml_char_t **uri);
static int
@@ -2292,7 +2293,7 @@ yaml_parser_scan_tag_directive_value(yaml_parser_t *parser,
/* Scan a prefix. */
- if (!yaml_parser_scan_tag_uri(parser, 1, NULL, start_mark, &prefix_value))
+ if (!yaml_parser_scan_tag_uri(parser, 1, 1, NULL, start_mark, &prefix_value))
goto error;
/* Expect a whitespace or line break. */
@@ -2410,7 +2411,7 @@ yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token)
/* Consume the tag value. */
- if (!yaml_parser_scan_tag_uri(parser, 0, NULL, start_mark, &suffix))
+ if (!yaml_parser_scan_tag_uri(parser, 1, 0, NULL, start_mark, &suffix))
goto error;
/* Check for '>' and eat it. */
@@ -2438,14 +2439,14 @@ yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token)
{
/* Scan the suffix now. */
- if (!yaml_parser_scan_tag_uri(parser, 0, NULL, start_mark, &suffix))
+ if (!yaml_parser_scan_tag_uri(parser, 0, 0, NULL, start_mark, &suffix))
goto error;
}
else
{
/* It wasn't a handle after all. Scan the rest of the tag. */
- if (!yaml_parser_scan_tag_uri(parser, 0, handle, start_mark, &suffix))
+ if (!yaml_parser_scan_tag_uri(parser, 0, 0, handle, start_mark, &suffix))
goto error;
/* Set the handle to '!'. */
@@ -2474,9 +2475,11 @@ yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token)
if (!CACHE(parser, 1)) goto error;
if (!IS_BLANKZ(parser->buffer)) {
- yaml_parser_set_scanner_error(parser, "while scanning a tag",
- start_mark, "did not find expected whitespace or line break");
- goto error;
+ if (!parser->flow_level || !CHECK(parser->buffer, ',') ) {
+ yaml_parser_set_scanner_error(parser, "while scanning a tag",
+ start_mark, "did not find expected whitespace or line break");
+ goto error;
+ }
}
end_mark = parser->mark;
@@ -2565,7 +2568,7 @@ error:
*/
static int
-yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive,
+yaml_parser_scan_tag_uri(yaml_parser_t *parser, int uri_char, int directive,
yaml_char_t *head, yaml_mark_t start_mark, yaml_char_t **uri)
{
size_t length = head ? strlen((char *)head) : 0;
@@ -2601,8 +2604,11 @@ yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive,
* The set of characters that may appear in URI is as follows:
*
* '0'-'9', 'A'-'Z', 'a'-'z', '_', '-', ';', '/', '?', ':', '@', '&',
- * '=', '+', '$', ',', '.', '!', '~', '*', '\'', '(', ')', '[', ']',
- * '%'.
+ * '=', '+', '$', '.', '!', '~', '*', '\'', '(', ')', '%'.
+ *
+ * If we are inside a verbatim tag <...> (parameter uri_char is true)
+ * then also the following flow indicators are allowed:
+ * ',', '[', ']'
*/
while (IS_ALPHA(parser->buffer) || CHECK(parser->buffer, ';')
@@ -2610,12 +2616,15 @@ yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive,
|| CHECK(parser->buffer, ':') || CHECK(parser->buffer, '@')
|| CHECK(parser->buffer, '&') || CHECK(parser->buffer, '=')
|| CHECK(parser->buffer, '+') || CHECK(parser->buffer, '$')
- || CHECK(parser->buffer, ',') || CHECK(parser->buffer, '.')
+ || CHECK(parser->buffer, '.') || CHECK(parser->buffer, '%')
|| CHECK(parser->buffer, '!') || CHECK(parser->buffer, '~')
|| CHECK(parser->buffer, '*') || CHECK(parser->buffer, '\'')
|| CHECK(parser->buffer, '(') || CHECK(parser->buffer, ')')
- || CHECK(parser->buffer, '[') || CHECK(parser->buffer, ']')
- || CHECK(parser->buffer, '%'))
+ || (uri_char && (
+ CHECK(parser->buffer, ',')
+ || CHECK(parser->buffer, '[') || CHECK(parser->buffer, ']')
+ )
+ ))
{
/* Check if it is a URI-escape sequence. */
@@ -2860,7 +2869,7 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token,
if (!CACHE(parser, 1)) goto error;
- while ((int)parser->mark.column == indent && !IS_Z(parser->buffer))
+ while ((int)parser->mark.column == indent && !(IS_Z(parser->buffer)))
{
/*
* We are at the beginning of a non-empty line.
@@ -3430,11 +3439,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;
@@ -3444,8 +3464,8 @@ 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, '{')
|| CHECK(parser->buffer, '}'))))
break;
@@ -3512,7 +3532,7 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token)
if (leading_blanks && (int)parser->mark.column < indent
&& IS_TAB(parser->buffer)) {
yaml_parser_set_scanner_error(parser, "while scanning a plain scalar",
- start_mark, "found a tab character that violate indentation");
+ start_mark, "found a tab character that violates indentation");
goto error;
}