From 919d6562bf3a787fa51a82ea5df57f07b0b4c33b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Date: Tue, 22 Mar 2011 15:59:28 +0100 Subject: [PATCH] Check for the minimum supported version The parser doesn't support version below YAML 1.1: raise an error if the document if 1.0 or below. --- include/yaml_parser.hrl | 2 ++ src/yaml_parser.erl | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/yaml_parser.hrl b/include/yaml_parser.hrl index 0265023..bdb1222 100644 --- a/include/yaml_parser.hrl +++ b/include/yaml_parser.hrl @@ -2,6 +2,8 @@ %% Data types specifications. %% ------------------------------------------------------------------- +-define(MIN_YAML_MAJOR_VERSION_SUPPORTED, 1). +-define(MIN_YAML_MINOR_VERSION_SUPPORTED, 1). -define(MAX_YAML_MAJOR_VERSION_SUPPORTED, 1). -define(MAX_YAML_MINOR_VERSION_SUPPORTED, 2). -define(IMPLICIT_YAML_VERSION, { diff --git a/src/yaml_parser.erl b/src/yaml_parser.erl index 2ef8ac2..081b7f2 100644 --- a/src/yaml_parser.erl +++ b/src/yaml_parser.erl @@ -895,8 +895,28 @@ start_doc(#yaml_parser{doc_version = Version, tags = Tags} = Parser, (Major == ?MAX_YAML_MAJOR_VERSION_SUPPORTED andalso Minor =< ?MAX_YAML_MINOR_VERSION_SUPPORTED) -> Parser; + {Major, Minor} when Major < ?MIN_YAML_MAJOR_VERSION_SUPPORTED orelse + (Major == ?MIN_YAML_MAJOR_VERSION_SUPPORTED andalso + Minor < ?MIN_YAML_MINOR_VERSION_SUPPORTED) -> + %% The document's version is not supported at all (below + %% minimum supported version). + Error = #yaml_parser_error{ + name = version_not_supported, + token = Token, + line = Line, + column = Col + }, + Parser0 = add_error(Parser, Error, + "Version ~b.~b not supported (minimum version ~b.~b)~n", + [ + Major, Minor, + ?MIN_YAML_MAJOR_VERSION_SUPPORTED, + ?MIN_YAML_MINOR_VERSION_SUPPORTED + ]), + return(Parser0); {Major, Minor} when Major > ?MAX_YAML_MAJOR_VERSION_SUPPORTED -> - %% The document's version is not supported at all. + %% The document's version is not supported at all (major + %% above maximum supporter major). Error = #yaml_parser_error{ name = version_not_supported, token = Token,