aboutsummaryrefslogtreecommitdiffstats
path: root/lib/xmerl/src/xmerl_sax_parser_base.erlsrc
diff options
context:
space:
mode:
authorLars Thorsen <[email protected]>2017-02-10 12:51:25 +0100
committerLars Thorsen <[email protected]>2017-02-22 10:00:19 +0100
commit760a3fa3c57fa2b56b44a9c25cbab4df0f71987e (patch)
tree0a19021823a0e01ea9af48c94fd44fb094d19ebb /lib/xmerl/src/xmerl_sax_parser_base.erlsrc
parent00294041cd3c6f66598a50b57abf27e6a35e277f (diff)
downloadotp-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/xmerl_sax_parser_base.erlsrc')
-rw-r--r--lib/xmerl/src/xmerl_sax_parser_base.erlsrc16
1 files changed, 15 insertions, 1 deletions
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()