Skip to content

Commit

Permalink
Merge pull request #1369 from JYZR/fix-xmerl_scan-acc
Browse files Browse the repository at this point in the history
Improves accumulator fun in xmerl_scan so that only one #xmlText record is returned for strings which have character references.

OTP-14377
Improves accumulator fun in xmerl_scan
  • Loading branch information
lthor committed Apr 27, 2017
2 parents 50c902f + 027c94a commit 74149d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/xmerl/src/xmerl_scan.erl
Expand Up @@ -474,8 +474,8 @@ event(_X, S) ->
%% into multiple objects (in which case {Acc',Pos',S'} should be returned.)
%% If {Acc',S'} is returned, Pos will be incremented by 1 by default.
%% Below is an example of an acceptable operation
acc(X = #xmlText{value = Text}, Acc, S) ->
{[X#xmlText{value = Text}|Acc], S};
acc(#xmlText{value = Text}, [X = #xmlText{value = AccText}], S) ->
{[X#xmlText{value = AccText ++ Text}], S};
acc(X, Acc, S) ->
{[X|Acc], S}.

Expand Down
9 changes: 6 additions & 3 deletions lib/xmerl/test/xmerl_SUITE.erl
Expand Up @@ -55,7 +55,7 @@ groups() ->
{misc, [],
[latin1_alias, syntax_bug1, syntax_bug2, syntax_bug3,
pe_ref1, copyright, testXSEIF, export_simple1, export,
default_attrs_bug, xml_ns]},
default_attrs_bug, xml_ns, scan_splits_string_bug]},
{eventp_tests, [], [sax_parse_and_export]},
{ticket_tests, [],
[ticket_5998, ticket_7211, ticket_7214, ticket_7430,
Expand Down Expand Up @@ -268,6 +268,10 @@ xml_ns(Config) ->
} = xmerl_scan:string(Doc2, [{namespace_conformant, true}]),
ok.

scan_splits_string_bug(_Config) ->
{#xmlElement{ content = [#xmlText{ value = "Jimmy Zöger" }] }, []}
= xmerl_scan:string("<name>Jimmy Z&#246;ger</name>").

pe_ref1(Config) ->
file:set_cwd(datadir(Config)),
{#xmlElement{},[]} = xmerl_scan:file(datadir_join(Config,[misc,"PE_ref1.xml"]),[{validation,true}]).
Expand Down Expand Up @@ -533,8 +537,7 @@ ticket_7430(Config) ->
{xmlElement,a,a,[],
{xmlNamespace,[],[]},
[],1,[],
[{xmlText,[{a,1}],1,[],"é",text},
{xmlText,[{a,1}],2,[],"\né",text}],
[{xmlText,[{a,1}],1,[],"é\né",text}],
[],_,undeclared} ->
ok;
_ ->
Expand Down

0 comments on commit 74149d7

Please sign in to comment.