Skip to content

Commit c137ad2

Browse files
committed
[xmerl] XSD Validation fails for mixed content
The validation failed due to not handling the optional text blocks correctly in an XSD complex type with attribute mixed=true.
1 parent c388a2d commit c137ad2

File tree

9 files changed

+230
-2
lines changed

9 files changed

+230
-2
lines changed

lib/xmerl/src/xmerl_xsd.erl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2620,6 +2620,9 @@ check_element_type(XML=[#xmlText{}|_],
26202620
{ResolvedType,_} = resolve({simple_or_complex_Type,BT},S),
26212621
check_element_type(XML,ResolvedType,Env,Block,S,Checked);
26222622

2623+
check_element_type(_C, optional_text, _Env, _Block, S, _Checked) ->
2624+
{[], [], S};
2625+
26232626
%% single schema object
26242627
check_element_type(XML=[_H|_],
26252628
#schema_complex_type{name=Name,block=Bl,content=C},
@@ -3055,12 +3058,16 @@ allow_empty_content([{extension,{_BT,_CM=[]}}]) ->
30553058
true;
30563059
allow_empty_content([{_,{_,{0,_}}}|Rest]) ->
30573060
allow_empty_content(Rest);
3061+
allow_empty_content([{any,{_,{0,_},_}}|Rest]) ->
3062+
allow_empty_content(Rest);
30583063
allow_empty_content([{_,{Content,_}}|Rest]) ->
30593064
case allow_empty_content(Content) of
30603065
true ->
30613066
allow_empty_content(Rest);
30623067
_ -> false
30633068
end;
3069+
allow_empty_content([optional_text|Rest]) ->
3070+
allow_empty_content(Rest);
30643071
allow_empty_content(_) ->
30653072
false.
30663073

@@ -3913,6 +3920,8 @@ is_optional(G={group,_},S) ->
39133920
{#schema_group{content=[CM]},_} ->
39143921
is_optional(CM,S)
39153922
end;
3923+
is_optional(optional_text,_) ->
3924+
true;
39163925
is_optional(_,_) ->
39173926
false.
39183927

lib/xmerl/test/xmerl_SUITE.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ export(Config) ->
309309
{ok, B} = file:read_file(TestFile),
310310
ok.
311311

312-
export_cdata(Config) ->
312+
export_cdata(_Config) ->
313313
InData = <<"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
314314
<doc>
315315
<a>Test...</a>

lib/xmerl/test/xmerl_xsd_SUITE.erl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ groups() ->
6666
sis2, state2file_file2state, union]},
6767
{ticket_tests, [],
6868
[ticket_6910, ticket_7165, ticket_7190, ticket_7288,
69-
ticket_7736, ticket_8599, ticket_9410]},
69+
ticket_7736, ticket_8599, ticket_9410, ticket_19792]},
7070
{facets, [],
7171
[length, minLength, maxLength, pattern, enumeration,
7272
whiteSpace, maxInclusive, maxExclusive, minExclusive,
@@ -970,6 +970,22 @@ ticket_9410(Config) ->
970970
file:set_cwd(datadir_join(Config,[".."])),
971971
{ok, _S} = xmerl_xsd:process_schema("xmerl_xsd_SUITE_data/small.xsd").
972972

973+
974+
ticket_19792(Config) ->
975+
{ok, S} = xmerl_xsd:process_schema(datadir_join(Config,["ticket_19792.xsd"])),
976+
{E0,_} = xmerl_scan:file(datadir_join(Config,["ticket_19792_0.xml"])),
977+
{{xmlElement,file,file,_,_,_,_,_,_,_,_,_},_GlobalState1} = xmerl_xsd:validate(E0, S),
978+
{E1,_} = xmerl_scan:file(datadir_join(Config,["ticket_19792_1.xml"])),
979+
{{xmlElement,file,file,_,_,_,_,_,_,_,_,_},_GlobalState1} = xmerl_xsd:validate(E1, S),
980+
{E2,_} = xmerl_scan:file(datadir_join(Config,["ticket_19792_2.xml"])),
981+
{{xmlElement,file,file,_,_,_,_,_,_,_,_,_},_GlobalState2} = xmerl_xsd:validate(E2, S),
982+
{E3,_} = xmerl_scan:file(datadir_join(Config,["ticket_19792_3.xml"])),
983+
{{xmlElement,file,file,_,_,_,_,_,_,_,_,_},_GlobalState3} = xmerl_xsd:validate(E3, S),
984+
{E4,_} = xmerl_scan:file(datadir_join(Config,["ticket_19792_4.xml"])),
985+
{{xmlElement,file,file,_,_,_,_,_,_,_,_,_},_GlobalState4} = xmerl_xsd:validate(E4, S),
986+
ok.
987+
988+
973989
%%======================================================================
974990
%% Support Functions
975991
%%======================================================================
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
%%
4+
%% %CopyrightBegin%
5+
%%
6+
%% SPDX-License-Identifier: Apache-2.0
7+
%%
8+
%% Copyright Ericsson AB 2025. All Rights Reserved.
9+
%%
10+
%% Licensed under the Apache License, Version 2.0 (the "License");
11+
%% you may not use this file except in compliance with the License.
12+
%% You may obtain a copy of the License at
13+
%%
14+
%% http://www.apache.org/licenses/LICENSE-2.0
15+
%%
16+
%% Unless required by applicable law or agreed to in writing, software
17+
%% distributed under the License is distributed on an "AS IS" BASIS,
18+
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
%% See the License for the specific language governing permissions and
20+
%% limitations under the License.
21+
%%
22+
%% %CopyrightEnd%
23+
-->
24+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
25+
<xs:element name="file">
26+
<xs:complexType>
27+
<xs:sequence>
28+
<xs:element ref="body"/>
29+
</xs:sequence>
30+
</xs:complexType>
31+
</xs:element>
32+
33+
<xs:element name="sequenceNumber" type="xs:unsignedShort"/>
34+
35+
<xs:element name="body">
36+
<xs:complexType>
37+
<xs:sequence>
38+
<xs:element ref="sequenceNumber"/>
39+
<xs:element ref="description"/>
40+
</xs:sequence>
41+
</xs:complexType>
42+
</xs:element>
43+
44+
<xs:element name="description">
45+
<xs:complexType mixed="true">
46+
<xs:sequence>
47+
<xs:any minOccurs="0"/>
48+
</xs:sequence>
49+
</xs:complexType>
50+
</xs:element>
51+
</xs:schema>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
%CopyrightBegin%
4+
5+
Copyright Ericsson AB 2006-2025. All Rights Reserved.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
%CopyrightEnd%
20+
-->
21+
<file>
22+
<body>
23+
<sequenceNumber>100</sequenceNumber>
24+
<description></description>
25+
</body>
26+
</file>
27+
28+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
%%
4+
%% %CopyrightBegin%
5+
%%
6+
%% SPDX-License-Identifier: Apache-2.0
7+
%%
8+
%% Copyright Ericsson AB 2025. All Rights Reserved.
9+
%%
10+
%% Licensed under the Apache License, Version 2.0 (the "License");
11+
%% you may not use this file except in compliance with the License.
12+
%% You may obtain a copy of the License at
13+
%%
14+
%% http://www.apache.org/licenses/LICENSE-2.0
15+
%%
16+
%% Unless required by applicable law or agreed to in writing, software
17+
%% distributed under the License is distributed on an "AS IS" BASIS,
18+
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
%% See the License for the specific language governing permissions and
20+
%% limitations under the License.
21+
%%
22+
%% %CopyrightEnd%
23+
-->
24+
<file>
25+
<body>
26+
<sequenceNumber>100</sequenceNumber>
27+
<description>teststring</description>
28+
</body>
29+
</file>
30+
31+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
%%
4+
%% %CopyrightBegin%
5+
%%
6+
%% SPDX-License-Identifier: Apache-2.0
7+
%%
8+
%% Copyright Ericsson AB 2025. All Rights Reserved.
9+
%%
10+
%% Licensed under the Apache License, Version 2.0 (the "License");
11+
%% you may not use this file except in compliance with the License.
12+
%% You may obtain a copy of the License at
13+
%%
14+
%% http://www.apache.org/licenses/LICENSE-2.0
15+
%%
16+
%% Unless required by applicable law or agreed to in writing, software
17+
%% distributed under the License is distributed on an "AS IS" BASIS,
18+
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
%% See the License for the specific language governing permissions and
20+
%% limitations under the License.
21+
%%
22+
%% %CopyrightEnd%
23+
-->
24+
<file>
25+
<body>
26+
<sequenceNumber>100</sequenceNumber>
27+
<description>teststring<sequenceNumber>100</sequenceNumber></description>
28+
</body>
29+
</file>
30+
31+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
%%
4+
%% %CopyrightBegin%
5+
%%
6+
%% SPDX-License-Identifier: Apache-2.0
7+
%%
8+
%% Copyright Ericsson AB 2025. All Rights Reserved.
9+
%%
10+
%% Licensed under the Apache License, Version 2.0 (the "License");
11+
%% you may not use this file except in compliance with the License.
12+
%% You may obtain a copy of the License at
13+
%%
14+
%% http://www.apache.org/licenses/LICENSE-2.0
15+
%%
16+
%% Unless required by applicable law or agreed to in writing, software
17+
%% distributed under the License is distributed on an "AS IS" BASIS,
18+
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
%% See the License for the specific language governing permissions and
20+
%% limitations under the License.
21+
%%
22+
%% %CopyrightEnd%
23+
-->
24+
<file>
25+
<body>
26+
<sequenceNumber>100</sequenceNumber>
27+
<description><sequenceNumber>100</sequenceNumber>teststring</description>
28+
</body>
29+
</file>
30+
31+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
%%
4+
%% %CopyrightBegin%
5+
%%
6+
%% SPDX-License-Identifier: Apache-2.0
7+
%%
8+
%% Copyright Ericsson AB 2025. All Rights Reserved.
9+
%%
10+
%% Licensed under the Apache License, Version 2.0 (the "License");
11+
%% you may not use this file except in compliance with the License.
12+
%% You may obtain a copy of the License at
13+
%%
14+
%% http://www.apache.org/licenses/LICENSE-2.0
15+
%%
16+
%% Unless required by applicable law or agreed to in writing, software
17+
%% distributed under the License is distributed on an "AS IS" BASIS,
18+
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
%% See the License for the specific language governing permissions and
20+
%% limitations under the License.
21+
%%
22+
%% %CopyrightEnd%
23+
-->
24+
<file>
25+
<body>
26+
<sequenceNumber>100</sequenceNumber>
27+
<description>teststring<sequenceNumber>100</sequenceNumber>teststring</description>
28+
</body>
29+
</file>
30+
31+

0 commit comments

Comments
 (0)