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.
This commit is contained in:
Jean-Sébastien Pédron 2011-03-22 15:59:28 +01:00
parent 554c88e8bb
commit 919d6562bf
2 changed files with 23 additions and 1 deletions

View File

@ -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, {

View File

@ -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,