Skip to content

Commit a7b7933

Browse files
committed
Fix xml regexp bug in XSD validation
XML regular expression evaluator in XSD validation didn't handle '\s' and '\S' correctly. Removed some compiler warnings in test code.
1 parent c388a2d commit a7b7933

12 files changed

Lines changed: 913 additions & 1588 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,5 +343,7 @@ JAVADOC-GENERATED
343343

344344
/lib/xmerl/src/xmerl_sax_parser_*.erl
345345
/lib/xmerl/src/xmerl_b64Bin.erl
346+
/lib/xmerl/src/xmerl_xsd_re_parse.erl
346347
/lib/xmerl/src/xmerl_xpath_parse.erl
347348
/lib/xmerl/test/xmerl_test.erl
349+

lib/xmerl/doc/examples/xmerl_test.erl

Lines changed: 73 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test3() ->
2828
io:format("From xmerl:export/2 xmerl_html filter~n ~p~n", [B]),
2929
C = xmerl:export([A], xmerl_text),
3030
io:format("From xmerl:export/2 xmerl_text filter~n ~p~n", [C]).
31-
31+
3232

3333
test4() ->
3434
FetchFun = fun(_DTDSpec, S) -> {ok, not_fetched, S} end,
@@ -61,14 +61,14 @@ test6() ->
6161

6262

6363
simple() ->
64-
[{document,
64+
[{document,
6565
[{title, ["Doc Title"]},
6666
{author, ["Ulf Wiger"]},
6767
{section,[{heading, ["heading1"]},
6868
{'P', ["This is a paragraph of text."]},
6969
{section,[{heading, ["heading2"]},
7070
{'P', ["This is another paragraph."]},
71-
{table,[{border, ["1"]},
71+
{table,[{border, ["1"]},
7272
{heading,[{col, ["head1"]},
7373
{col, ["head2"]}]},
7474
{row, [{col, ["col11"]},
@@ -166,7 +166,7 @@ w3cvalidate() ->
166166
C = xmerl:export([A], xmerl_test),
167167
io:format("From xmerl:export/2 xmerl_text filter~n ~p~n", [C])
168168
end.
169-
169+
170170

171171
'TESTSUITE'(_Data, Attrs, _Parents, _E) ->
172172
_Profile = find_attribute('PROFILE', Attrs),
@@ -186,7 +186,7 @@ w3cvalidate() ->
186186
Id = find_attribute('ID', Attrs),
187187
io:format("Test: ~p ",[Id]),
188188
Entities = find_attribute('ENTITIES', Attrs), % Always handle all entities
189-
Output1 = find_attribute('OUTPUT', Attrs), %
189+
Output1 = find_attribute('OUTPUT', Attrs), %
190190
Output3 = find_attribute('OUTPUT3', Attrs), % FIXME!
191191
Sections = find_attribute('SECTIONS', Attrs),
192192
Recommendation = find_attribute('RECOMMENDATION', Attrs), % FIXME!
@@ -253,18 +253,18 @@ test_valid(URI, Data, Sections, Entities, OutputForm, Recommendation, Version,
253253
print_error({Res, Tail}, URI, Sections, Entities, OutputForm,
254254
Recommendation,
255255
Version, Namespace, Data),
256-
if
257-
?CONT == false -> throw({'EXIT', failed_test});
258-
true -> error
259-
end
256+
case ?CONT of
257+
false -> throw({'EXIT', failed_test});
258+
true -> error
259+
end
260260
end;
261261
Error ->
262262
print_error(Error, URI, Sections, Entities, OutputForm, Recommendation,
263263
Version, Namespace, Data),
264-
if
265-
?CONT == false -> throw({'EXIT', failed_test});
266-
true -> error
267-
end
264+
case ?CONT of
265+
false -> throw({'EXIT', failed_test});
266+
true -> error
267+
end
268268
end,
269269
io:format("validating ", []),
270270
case validating_parser_q(URI) of
@@ -277,18 +277,18 @@ test_valid(URI, Data, Sections, Entities, OutputForm, Recommendation, Version,
277277
print_error({Res2, Tail2}, URI, Sections, Entities, OutputForm,
278278
Recommendation,
279279
Version, Namespace, Data),
280-
if
281-
?CONT == false -> throw({'EXIT', failed_test});
282-
true -> error
283-
end
280+
case ?CONT of
281+
false -> throw({'EXIT', failed_test});
282+
true -> error
283+
end
284284
end;
285285
Error2 ->
286286
print_error(Error2, URI, Sections, Entities, OutputForm, Recommendation,
287287
Version, Namespace, Data),
288-
if
289-
?CONT == false -> throw({'EXIT', failed_test});
290-
true -> error
291-
end
288+
case ?CONT of
289+
false -> throw({'EXIT', failed_test});
290+
true -> error
291+
end
292292
end.
293293

294294

@@ -307,18 +307,18 @@ test_invalid(URI, Data, Sections, Entities, OutputForm, Recommendation, Version,
307307
print_error({Res, Tail}, URI, Sections, Entities, OutputForm,
308308
Recommendation,
309309
Version, Namespace, Data),
310-
if
311-
?CONT == false -> throw({'EXIT', failed_test});
312-
true -> error
313-
end
310+
case ?CONT of
311+
false -> throw({'EXIT', failed_test});
312+
true -> error
313+
end
314314
end;
315315
Error ->
316316
print_error(Error, URI, Sections, Entities, OutputForm, Recommendation,
317317
Version, Namespace, Data),
318-
if
319-
?CONT == false -> throw({'EXIT', failed_test});
320-
true -> error
321-
end
318+
case ?CONT of
319+
false -> throw({'EXIT', failed_test});
320+
true -> error
321+
end
322322
end,
323323
io:format("validating ", []),
324324
case validating_parser_q(URI) of
@@ -331,18 +331,18 @@ test_invalid(URI, Data, Sections, Entities, OutputForm, Recommendation, Version,
331331
print_error({Res2, Tail2}, URI, Sections, Entities, OutputForm,
332332
Recommendation,
333333
Version, Namespace, Data),
334-
if
335-
?CONT == false -> throw({'EXIT', failed_test});
336-
true -> error
337-
end
334+
case ?CONT of
335+
false -> throw({'EXIT', failed_test});
336+
true -> error
337+
end
338338
end;
339339
{error, enoent} ->
340340
print_error("Testfile not found", URI, Sections, Entities, OutputForm,
341341
Recommendation, Version, Namespace, Data),
342-
if
343-
?CONT == false -> throw({'EXIT', failed_test});
344-
true -> error
345-
end;
342+
case ?CONT of
343+
false -> throw({'EXIT', failed_test});
344+
true -> error
345+
end;
346346
_Error2 ->
347347
io:format("OK~n", []),
348348
ok
@@ -363,18 +363,18 @@ test_notwf(URI, Data, Sections, Entities, OutputForm, Recommendation, Version,
363363
print_error({Res, Tail}, URI, Sections, Entities, OutputForm,
364364
Recommendation,
365365
Version, Namespace, Data),
366-
if
367-
?CONT == false -> throw({'EXIT', failed_test});
368-
true -> error
369-
end
366+
case ?CONT of
367+
false -> throw({'EXIT', failed_test});
368+
true -> error
369+
end
370370
end;
371371
{error,enoent} ->
372372
print_error("Testfile not found",URI,Sections,Entities,OutputForm,
373373
Recommendation,Version,Namespace,Data),
374-
if
375-
?CONT==false -> throw({'EXIT', failed_test});
376-
true -> error
377-
end;
374+
case ?CONT of
375+
false -> throw({'EXIT', failed_test});
376+
true -> error
377+
end;
378378
_Error ->
379379
io:format("OK ",[]),
380380
ok
@@ -390,18 +390,18 @@ test_notwf(URI, Data, Sections, Entities, OutputForm, Recommendation, Version,
390390
print_error({Res2, Tail2}, URI, Sections, Entities, OutputForm,
391391
Recommendation,
392392
Version, Namespace, Data),
393-
if
394-
?CONT == false -> throw({'EXIT', failed_test});
395-
true -> error
396-
end
393+
case ?CONT of
394+
false -> throw({'EXIT', failed_test});
395+
true -> error
396+
end
397397
end;
398398
{error,enoent} ->
399399
print_error("Testfile not found", URI, Sections, Entities, OutputForm,
400400
Recommendation, Version, Namespace, Data),
401-
if
402-
?CONT == false -> throw({'EXIT', failed_test});
403-
true -> error
404-
end;
401+
case ?CONT of
402+
false -> throw({'EXIT', failed_test});
403+
true -> error
404+
end;
405405
_Error2 ->
406406
io:format("OK~n", []),
407407
ok
@@ -418,17 +418,17 @@ test_error(URI, Data, Sections, Entities, OutputForm, Recommendation, Version,
418418
{error, enoent} ->
419419
print_error("Testfile not found", URI, Sections, Entities, OutputForm,
420420
Recommendation, Version, Namespace, Data),
421-
if
422-
?CONT == false -> throw({'EXIT', failed_test});
423-
true -> error
424-
end;
421+
case ?CONT of
422+
false -> throw({'EXIT', failed_test});
423+
true -> error
424+
end;
425425
Res ->
426426
print_error(Res, URI, Sections, Entities, OutputForm, Recommendation,
427427
Version, Namespace, Data),
428-
if
429-
?CONT == false -> throw({'EXIT', failed_test});
430-
true -> error
431-
end
428+
case ?CONT of
429+
false -> throw({'EXIT', failed_test});
430+
true -> error
431+
end
432432
end,
433433
io:format("validating ", []),
434434
case validating_parser_q(URI) of
@@ -438,17 +438,17 @@ test_error(URI, Data, Sections, Entities, OutputForm, Recommendation, Version,
438438
{error, enoent} ->
439439
print_error("Testfile not found", URI, Sections, Entities, OutputForm,
440440
Recommendation, Version, Namespace, Data),
441-
if
442-
?CONT == false -> throw({'EXIT', failed_test});
443-
true -> error
444-
end;
441+
case ?CONT of
442+
false -> throw({'EXIT', failed_test});
443+
true -> error
444+
end;
445445
Res2 ->
446446
print_error(Res2, URI, Sections, Entities, OutputForm, Recommendation,
447447
Version, Namespace, Data),
448-
if
449-
?CONT == false -> throw({'EXIT', failed_test});
450-
true -> error
451-
end
448+
case ?CONT of
449+
false -> throw({'EXIT', failed_test});
450+
true -> error
451+
end
452452
end.
453453

454454

@@ -506,10 +506,10 @@ print_error(Error, URI, Sections, Entities, OutputForm, Recommendation, Version,
506506
io:format(Data).
507507

508508

509-
510-
511-
512-
509+
510+
511+
512+
513513

514514

515515

@@ -521,5 +521,3 @@ para(_Data, _Attrs, US) ->
521521
Int when is_integer(Int) -> Int+1;
522522
undefined -> 1
523523
end.
524-
525-

lib/xmerl/src/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ MODULES = $(EDOC_MODULES) \
6868
xmerl_html \
6969
xmerl_lib \
7070
xmerl_otpsgml \
71-
xmerl_regexp \
7271
xmerl_sgml \
7372
xmerl_simple \
7473
xmerl_text \
@@ -90,7 +89,9 @@ MODULES = $(EDOC_MODULES) \
9089
xmerl_sax_parser_utf16be \
9190
xmerl_sax_parser_utf16le \
9291
xmerl_sax_simple_dom \
93-
xmerl_sax_old_dom
92+
xmerl_sax_old_dom \
93+
xmerl_xsd_re \
94+
xmerl_xsd_re_parse
9495

9596

9697

@@ -185,6 +186,9 @@ xmerl_xpath_parse.erl: xmerl_xpath_parse.yrl
185186
xmerl_b64Bin.erl: xmerl_b64Bin.yrl
186187
$(yecc_verbose)$(ERLC) -o $(ESRC) $(DETERMINISM_FLAG) $<
187188

189+
xmerl_xsd_re_parse.erl: xmerl_xsd_re_parse.yrl
190+
$(yecc_verbose)$(ERLC) -o $(ESRC) $(DETERMINISM_FLAG) $<
191+
188192
xmerl_sax_parser_list.erl: xmerl_sax_parser_list.erlsrc xmerl_sax_parser_base.erlsrc
189193
$(gen_verbose)cat xmerl_sax_parser_list.erlsrc xmerl_sax_parser_base.erlsrc >$@
190194

lib/xmerl/src/xmerl.app.src

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
xmerl_html,
1010
xmerl_lib,
1111
xmerl_otpsgml,
12-
xmerl_regexp,
1312
xmerl_sax_parser,
1413
xmerl_sax_parser_list,
1514
xmerl_sax_parser_latin1,
@@ -35,6 +34,8 @@
3534
xmerl_xpath_scan,
3635
xmerl_xs,
3736
xmerl_xsd,
37+
xmerl_xsd_re,
38+
xmerl_xsd_re_parse,
3839
xmerl_xsd_type
3940
]},
4041

0 commit comments

Comments
 (0)