mirror of
https://github.com/valitydev/yamerl.git
synced 2024-11-06 02:45:23 +00:00
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:
parent
554c88e8bb
commit
919d6562bf
@ -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, {
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user