diff options
Diffstat (limited to 'lib/xmerl/src/xmerl_sax_parser_base.erlsrc')
-rw-r--r-- | lib/xmerl/src/xmerl_sax_parser_base.erlsrc | 65 |
1 files changed, 49 insertions, 16 deletions
diff --git a/lib/xmerl/src/xmerl_sax_parser_base.erlsrc b/lib/xmerl/src/xmerl_sax_parser_base.erlsrc index 7b64d7c302..e198f2fef5 100644 --- a/lib/xmerl/src/xmerl_sax_parser_base.erlsrc +++ b/lib/xmerl/src/xmerl_sax_parser_base.erlsrc @@ -113,6 +113,10 @@ parse_dtd(Xml, State) -> State3 = event_callback(endDocument, State2), ets:delete(RefTable), {ok, State3#xmerl_sax_parser_state.event_state, Rest}; + {endDocument, Rest, State2} when is_record(State2, xmerl_sax_parser_state) -> + State3 = event_callback(endDocument, State2), + ets:delete(RefTable), + {ok, State3#xmerl_sax_parser_state.event_state, Rest}; Other -> _State2 = event_callback(endDocument, State1), ets:delete(RefTable), @@ -207,8 +211,14 @@ parse_prolog(?STRING_EMPTY, State) -> parse_prolog(?STRING("<") = Bytes, State) -> cf(Bytes, State, fun parse_prolog/2); parse_prolog(?STRING_REST("<?", Rest), State) -> - {Rest1, State1} = parse_pi(Rest, State), - parse_prolog(Rest1, State1); + case parse_pi(Rest, State) of + {Rest1, State1} -> + parse_prolog(Rest1, State1); + {endDocument, Rest1, State1} -> + parse_prolog(Rest1, State1) + % IValue = ?TO_INPUT_FORMAT("<?"), + % {?APPEND_STRING(IValue, Rest1), State1} + end; parse_prolog(?STRING_REST("<!", Rest), State) -> parse_prolog_1(Rest, State); parse_prolog(?STRING_REST("<", Rest), State) -> @@ -409,10 +419,11 @@ parse_pi(?STRING_UNBOUND_REST(C, Rest) = Bytes, State) -> parse_name(Rest, State, [C]), case string:to_lower(PiTarget) of "xml" -> - case State#xmerl_sax_parser_state.end_tags of - [] -> - {Bytes, State}; - _ -> + case check_if_new_doc_allowed(State#xmerl_sax_parser_state.input_type, + State#xmerl_sax_parser_state.end_tags) of + true -> + {endDocument, Bytes, State}; + false -> ?fatal_error(State1, "<?xml ...?> not first in document") end; _ -> @@ -426,6 +437,11 @@ parse_pi(?STRING_UNBOUND_REST(C, Rest) = Bytes, State) -> parse_pi(Bytes, State) -> unicode_incomplete_check([Bytes, State, fun parse_pi/2], undefined). +check_if_new_doc_allowed(stream, []) -> + true; +check_if_new_doc_allowed(_, _) -> + false. + %%---------------------------------------------------------------------- %% Function: parse_pi_1(Rest, State) -> Result %% Input: Rest = string() | binary() @@ -657,8 +673,13 @@ parse_misc(?STRING_EMPTY, State, Eod) -> parse_misc(?STRING("<") = Rest, State, Eod) -> cf(Rest, State, Eod, fun parse_misc/3); parse_misc(?STRING_REST("<?", Rest), State, Eod) -> - {Rest1, State1} = parse_pi(Rest, State), - parse_misc(Rest1, State1, Eod); + case parse_pi(Rest, State) of + {Rest1, State1} -> + parse_misc(Rest1, State1, Eod); + {endDocument, _Rest1, State1} -> + IValue = ?TO_INPUT_FORMAT("<?"), + {?APPEND_STRING(IValue, Rest), State1} + end; parse_misc(?STRING("<!") = Rest, State, Eod) -> cf(Rest, State, Eod, fun parse_misc/3); parse_misc(?STRING("<!-") = Rest, State, Eod) -> @@ -1063,8 +1084,13 @@ parse_content(?STRING_REST("<!--", Rest), State, Acc, IgnorableWS) -> parse_content(Rest1, State2, [], true); parse_content(?STRING_REST("<?", Rest), State, Acc, IgnorableWS) -> State1 = send_character_event(length(Acc), IgnorableWS, lists:reverse(Acc), State), - {Rest1, State2} = parse_pi(Rest, State1), - parse_content(Rest1, State2, [], true); + case parse_pi(Rest, State1) of + {Rest1, State2} -> + parse_content(Rest1, State2, [], true); + {endDocument, _Rest1, State2} -> + IValue = ?TO_INPUT_FORMAT("<?"), + {?APPEND_STRING(IValue, Rest), State2} + end; parse_content(?STRING_REST("<!", Rest1) = Rest, #xmerl_sax_parser_state{end_tags = ET} = State, Acc, IgnorableWS) -> case ET of [] -> @@ -1649,8 +1675,9 @@ handle_external_entity({file, FileToOpen}, State) -> {?STRING_EMPTY, EntityState} = parse_external_entity_1(<<>>, State#xmerl_sax_parser_state{continuation_state=FD, - current_location=filename:dirname(FileToOpen), - entity=filename:basename(FileToOpen)}), + current_location=filename:dirname(FileToOpen), + entity=filename:basename(FileToOpen), + input_type=file}), file:close(FD), EntityState#xmerl_sax_parser_state.event_state end; @@ -1667,8 +1694,9 @@ handle_external_entity({http, Url}, State) -> {?STRING_EMPTY, EntityState} = parse_external_entity_1(<<>>, State#xmerl_sax_parser_state{continuation_state=FD, - current_location=filename:dirname(Url), - entity=filename:basename(Url)}), + current_location=filename:dirname(Url), + entity=filename:basename(Url), + input_type=file}), file:close(FD), file:delete(TmpFile), EntityState#xmerl_sax_parser_state.event_state @@ -1881,8 +1909,13 @@ parse_doctype_decl(?STRING_EMPTY, State) -> parse_doctype_decl(?STRING("<"), State) -> cf(?STRING("<"), State, fun parse_doctype_decl/2); parse_doctype_decl(?STRING_REST("<?", Rest), State) -> - {Rest1, State1} = parse_pi(Rest, State), - parse_doctype_decl(Rest1, State1); + case parse_pi(Rest, State) of + {Rest1, State1} -> + parse_doctype_decl(Rest1, State1); + {endDocument, _Rest1, State1} -> + IValue = ?TO_INPUT_FORMAT("<?"), + {?APPEND_STRING(IValue, Rest), State1} + end; parse_doctype_decl(?STRING_REST("%", Rest), State) -> {Ref, Rest1, State1} = parse_pe_reference(Rest, State), case Ref of |