From 658fee0d694f3388f88c5fdd2593ae7dc70cdc31 Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Wed, 9 Mar 2016 11:29:49 +0100 Subject: [PATCH] implement nonstrict mode optionally allow certian reader errors. needed for perl YAML validation tests. See https://github.com/ingydotnet/yaml-libyaml-pm/issues/44 --- src/parser.c | 6 ++++-- src/scanner.c | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/parser.c b/src/parser.c index a613792c..5a893daf 100644 --- a/src/parser.c +++ b/src/parser.c @@ -179,8 +179,10 @@ yaml_parser_parse(yaml_parser_t *parser, yaml_event_t *event) /* No events after the end of the stream or error. */ if (parser->stream_end_produced || - parser->error || - parser->state == YAML_PARSE_END_STATE) { + (parser->error && + /* continue in nonstrict and READER_ERROR */ + (!parser->problem_nonstrict || parser->error != YAML_READER_ERROR)) || + parser->state == YAML_PARSE_END_STATE) { return 1; } diff --git a/src/scanner.c b/src/scanner.c index de9d545d..6bfae0bf 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -751,7 +751,9 @@ yaml_parser_scan(yaml_parser_t *parser, yaml_token_t *token) /* No tokens after STREAM-END or error. */ if (parser->stream_end_produced - || parser->error) + || (parser->error + /* continue in nonstrict and READER_ERROR */ + && (!parser->problem_nonstrict || parser->error != YAML_READER_ERROR))) return 1; /* Ensure that the tokens queue contains enough tokens. */