Skip to content

Commit

Permalink
Merge branch 'lars/xmerl/entity-check-error/OTP-8947' into dev
Browse files Browse the repository at this point in the history
* lars/xmerl/entity-check-error/OTP-8947:
  Fix entity checking when option skip_external_dtd is used so there is no fatal error.
  • Loading branch information
lthor committed Dec 2, 2010
2 parents c7fa778 + abf26dd commit a13deef
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions lib/xmerl/src/xmerl_sax_parser_base.erlsrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%%-*-erlang-*-
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2008-2009. All Rights Reserved.
%% Copyright Ericsson AB 2008-2010. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
Expand Down Expand Up @@ -934,6 +934,13 @@ parse_att_value(?STRING_REST("&", Rest), State, Stop, Acc) ->
parse_att_value(Rest1, State2, Stop, ParsedValue ++ Acc);
{external_general, Name, _} ->
?fatal_error(State1, "External parsed entity reference in attribute value: " ++ Name);
{not_found, Name} ->
case State#xmerl_sax_parser_state.skip_external_dtd of
false ->
?fatal_error(State1, "Entity not declared: " ++ Name); %%VC: Entity Declared
true ->
parse_att_value(Rest1, State1, Stop, ";" ++ lists:reverse(Name) ++ "&" ++ Acc)
end;
{unparsed, Name, _} ->
?fatal_error(State1, "Unparsed entity reference in attribute value: " ++ Name)
end;
Expand Down Expand Up @@ -1098,6 +1105,13 @@ parse_content(?STRING_REST("&", Rest), State, Acc, _IgnorableWS) ->
{external_general, _, {PubId, SysId}} ->
State2 = parse_external_entity(State1, PubId, SysId),
parse_content(Rest1, State2, Acc, false);
{not_found, Name} ->
case State#xmerl_sax_parser_state.skip_external_dtd of
false ->
?fatal_error(State1, "Entity not declared: " ++ Name); %%VC: Entity Declared
true ->
parse_content(Rest1, State1, ";" ++ lists:reverse(Name) ++ "&" ++ Acc, false)
end;
{unparsed, Name, _} ->
?fatal_error(State1, "Unparsed entity reference in content: " ++ Name)
end;
Expand Down Expand Up @@ -1357,7 +1371,7 @@ look_up_reference(Name, HaveToExist, State) ->
yes ->
?fatal_error(State, "Entity not declared: " ++ Name); %%WFC: Entity Declared
no ->
?fatal_error(State, "Entity not declared: " ++ Name) %%VC: Entity Declared
{not_found, Name} %%VC: Entity Declared
end;
false ->
{not_found, Name}
Expand Down Expand Up @@ -1869,7 +1883,14 @@ parse_doctype_decl(?STRING_REST("%", Rest), State) ->
parse_doctype_decl(?APPEND_STRING(IValue, Rest1), State1);
{external_parameter, _, {PubId, SysId}} ->
State2 = parse_external_entity(State1#xmerl_sax_parser_state{file_type = entity}, PubId, SysId),
parse_doctype_decl(Rest1, State2)
parse_doctype_decl(Rest1, State2);
{not_found, Name} ->
case State#xmerl_sax_parser_state.skip_external_dtd of
false ->
?fatal_error(State1, "Entity not declared: " ++ Name); %%WFC: Entity Declared
true ->
parse_doctype_decl(Rest1, State1)
end
end;
parse_doctype_decl(?STRING_REST("<!", Rest1), State) ->
parse_doctype_decl_1(Rest1, State);
Expand Down Expand Up @@ -2443,7 +2464,7 @@ parse_ndata(Bytes, State) ->
%% Acc = string()
%% Result : {Value, Rest, State}
%% Value = string()
%% Description: Parse an attribute value
%% Description: Parse an entity value
%%----------------------------------------------------------------------
parse_entity_value(?STRING_EMPTY, State, undefined, Acc) ->
{Acc, [], State}; %% stop clause when parsing references
Expand Down Expand Up @@ -2473,7 +2494,7 @@ parse_entity_value(?STRING_REST("&", Rest), State, Stop, Acc) ->
{external_general, Name, _} ->
parse_entity_value(Rest1, State1, Stop, ";" ++ lists:reverse(Name) ++ "&" ++ Acc);
{not_found, Name} ->
parse_entity_value(Rest1, State1, Stop, ";" ++ lists:reverse(Name) ++ "&" ++ Acc);
parse_entity_value(Rest1, State1, Stop, ";" ++ lists:reverse(Name) ++ "&" ++ Acc);
{unparsed, Name, _} ->
?fatal_error(State1, "Unparsed entity reference in entity value: " ++ Name)
end;
Expand All @@ -2490,7 +2511,15 @@ parse_entity_value(?STRING_REST("%", Rest), #xmerl_sax_parser_state{file_type=Ty
IValue = ?TO_INPUT_FORMAT(" " ++ RefValue ++ " "),
parse_entity_value(?APPEND_STRING(IValue, Rest1), State1, Stop, Acc);
{external_parameter, _, {_PubId, _SysId}} ->
?fatal_error(State1, "Parameter references in entity value not supported yet.")
?fatal_error(State1, "Parameter references in entity value not supported yet.");
{not_found, Name} ->
case State#xmerl_sax_parser_state.skip_external_dtd of
false ->
?fatal_error(State1, "Entity not declared: " ++ Name); %%VC: Entity Declared
true ->
parse_entity_value(Rest1, State1, Stop, ";" ++ lists:reverse(Name) ++ "&" ++ Acc)
end

end
end;
parse_entity_value(?STRING_UNBOUND_REST(Stop, Rest), State, Stop, Acc) ->
Expand Down

0 comments on commit a13deef

Please sign in to comment.