diff options
author | Lars Thorsen <[email protected]> | 2017-02-10 12:51:25 +0100 |
---|---|---|
committer | Lars Thorsen <[email protected]> | 2017-02-22 10:00:19 +0100 |
commit | 760a3fa3c57fa2b56b44a9c25cbab4df0f71987e (patch) | |
tree | 0a19021823a0e01ea9af48c94fd44fb094d19ebb /lib/xmerl/src | |
parent | 00294041cd3c6f66598a50b57abf27e6a35e277f (diff) | |
download | otp-760a3fa3c57fa2b56b44a9c25cbab4df0f71987e.tar.gz otp-760a3fa3c57fa2b56b44a9c25cbab4df0f71987e.tar.bz2 otp-760a3fa3c57fa2b56b44a9c25cbab4df0f71987e.zip |
[xmerl] Fix XML "well-formedness" bug i SAX parser
Changed the XML Sax parser behaviour so it returns an error
if there are something more in the file after the the
matching document. If one using the xmerl_sax_parser:stream()
a rest is allowed which then can be sent to a new call of
xmerl_sax_parser:stream() to parse next document.
This is done to be compliant with XML conformance tests.
Diffstat (limited to 'lib/xmerl/src')
-rw-r--r-- | lib/xmerl/src/xmerl_sax_parser.hrl | 9 | ||||
-rw-r--r-- | lib/xmerl/src/xmerl_sax_parser_base.erlsrc | 16 |
2 files changed, 16 insertions, 9 deletions
diff --git a/lib/xmerl/src/xmerl_sax_parser.hrl b/lib/xmerl/src/xmerl_sax_parser.hrl index 932ab0cec5..7f9bf6c4d3 100644 --- a/lib/xmerl/src/xmerl_sax_parser.hrl +++ b/lib/xmerl/src/xmerl_sax_parser.hrl @@ -88,14 +88,7 @@ current_location, % Location of the currently parsed XML entity entity, % Parsed XML entity skip_external_dtd = false,% If true the external DTD is skipped during parsing - input_type % Source type: file | stream. - % This field is a preparation for an fix in R17 of a bug in - % the conformance against the standard. - % Today a file which contains two XML documents will be considered - % well-formed and the second is placed in the rest part of the - % return tuple, according to the conformance tests this should fail. - % In the future this will fail if xmerl_sax_aprser:file/2 is used but - % left to the user in the xmerl_sax_aprser:stream/2 case. + input_type % Source type: file | stream }). diff --git a/lib/xmerl/src/xmerl_sax_parser_base.erlsrc b/lib/xmerl/src/xmerl_sax_parser_base.erlsrc index 3ef2fce4d3..39dd3bbff3 100644 --- a/lib/xmerl/src/xmerl_sax_parser_base.erlsrc +++ b/lib/xmerl/src/xmerl_sax_parser_base.erlsrc @@ -72,7 +72,12 @@ parse(Xml, State) -> {ok, Rest, State2} -> State3 = event_callback(endDocument, State2), ets:delete(RefTable), - {ok, State3#xmerl_sax_parser_state.event_state, Rest}; + case check_if_rest_ok(State3#xmerl_sax_parser_state.input_type, Rest) of + true -> + {ok, State3#xmerl_sax_parser_state.event_state, Rest}; + false -> + format_error(fatal_error, State3, "Input found after legal document") + end; {fatal_error, {State2, Reason}} -> State3 = event_callback(endDocument, State2), ets:delete(RefTable), @@ -446,6 +451,15 @@ check_if_new_doc_allowed(stream, []) -> check_if_new_doc_allowed(_, _) -> false. +check_if_rest_ok(file, []) -> + true; +check_if_rest_ok(file, <<>>) -> + true; +check_if_rest_ok(stream, _) -> + true; +check_if_rest_ok(_, _) -> + false. + %%---------------------------------------------------------------------- %% Function: parse_pi_1(Rest, State) -> Result %% Input: Rest = string() | binary() |