[erlang-bugs] bug_xmerl_comment

Constantin Malikov kostiamalikov@REDACTED
Wed Oct 30 02:11:36 CET 2013


Hello , friends. I want to tell you about a bug in Erlang:

 I have a trouble with validating xml document by xsd schema in case of

use comment in the xml document. I attached simple sample, where you can
see this problem. To run it, compile xml_comment_test.erl and invoke
“invalid_xml_comment_test” method.

You can see the error message:

_________________________________________________________________
{error,

[{"context[1]",xmerl_xsd,

{undefined,

{internal_error,

{function_clause,

[{xmerl_xsd,check_choice,

[[{xmlComment,

[{result,2},{rule,2},{context,1}],

4,[],

" continue context=\"ctx_megaco_local_in\"/ "}],

[{element,

{{continue,

[anonymous,result,anonymous,rule,anonymous,

context],

[]},

{1,1}}}],

{1,1},

['_xmerl_no_name_','_xmerl_no_name_',

'_xmerl_no_name_'],

{xsd_state,"ecss_routing.xsd",

[93547814522301227513625523114529142023],

false,false,".",[],

[anonymous,result,anonymous,rule,anonymous,

context],

[],unqualified,unqualified,undefined,undefined,

[{"xs",'http://www.w3.org/2001/XMLSchema'},

{"xml",'http://www.w3.org/XML/1998/namespace'}],

[{undefined,

[{"xs",'http://www.w3.org/2001/XMLSchema'}]}],

[{"#this#","ecss_routing.xsd",undefined},

{"xml",[],

'http://www.w3.org/XML/1998/namespace'}],

28690,false,false,[],[],

#Fun<xmerl_xsd.1.36898106>,[],1,[],[],[],[],[],[],

[],[],[]},

[{xmlText,

[{result,2},{rule,2},{context,1}],

3,[],"\n ",text},

{xmlElement,continue,continue,[],

{xmlNamespace,[],[]},

[{result,2},{rule,2},{context,1}],

2,

[{xmlAttribute,context,[],[],[],

[{continue,2},

{result,2},

{rule,2},

{context,1}],

1,[],"ctx_megaco_local_in",false}],

[],[],

"/home/konstantin/erlang/tasks/diffR15B02/xml_comment_test",

undeclared},

{xmlText,

[{result,2},{rule,2},{context,1}],

1,[],"\n ",text}]],

[{file,"xmerl_xsd.erl"},{line,2806}]},

{xmerl_xsd,check_element_type,6,

[{file,"xmerl_xsd.erl"},{line,2601}]},

{xmerl_xsd,check_sequence,6,

[{file,"xmerl_xsd.erl"},{line,2754}]},

{xmerl_xsd,check_element_type,6,

[{file,"xmerl_xsd.erl"},{line,2601}]},

{xmerl_xsd,check_sequence,6,

[{file,"xmerl_xsd.erl"},{line,2754}]},

{xmerl_xsd,check_element_type,6,

[{file,"xmerl_xsd.erl"},{line,2601}]},

{xmerl_xsd,validate_xml,3,

[{file,"xmerl_xsd.erl"},{line,2418}]},

{xmerl_xsd,validate3,3,

[{file,"xmerl_xsd.erl"},{line,251}]}]}}}}]}
________________________________________________________________


 How can i see, in the xmerl_xsd.erl module, check_choice metod. No
function for processing comments.


 Tested by Erlang 16B02, xmerl 1.3.4 and R15B02, xmerl 1.3.2.

_______________________ctx_megaco.xml____________________________
<? xml version = "1.0"?>
<context>
    <rule>
        <result>
            <continue context="ctx_megaco_local_in"/>
            <! - Continue context = "ctx_megaco_local_in" / ->
        </ result>
    </ rule>
</ context>
________________________________________________________________

_________________________ecss_routing.xsd__________________________
<? xml version = "1.0" encoding = "UTF- 8" ? >
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="context">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="rule">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="result">
                <xs:complexType>
                  <xs:choice>
                    <xs:element name="incomplete" type="xs:string"/>
                    <! - xs: element name = "no_route" type = "nullType" /
->
                    <xs:element name="continue" type="continueType"/>
                  </ xs: choice>
                </ xs: complexType>
              </ xs: element>
            </ xs: sequence>
          </ xs: complexType>
        </ xs: element>
      </ xs: sequence>
    </ xs: complexType>
  </ xs: element>

  <xs:complexType name="continueType">
    <xs:attribute name="context" type="xs:string"/>
  </ xs: complexType>
</ xs: schema>
________________________________________________________________

_______________________xml_comment_test.erl__________________________

-module (xml_comment_test).

-export ([
        invalid_xml_comment_test / 0
        ]).

read_xml (FileName) ->
    {ok, Schema} = xmerl_xsd: process_schema ("ecss_routing.xsd"),
    {ok, BXml} = file: read_file (FileName),
    Xml = erlang: binary_to_list (BXml),
    {XmerXml, _} = xmerl_scan: string (Xml),
    xmerl_xsd: validate (XmerXml, Schema).

invalid_xml_comment_test () ->
    Result = read_xml ("ctx_megaco.xml"),
    io: format ("~ p ~ n", [Result]).
________________________________________________________________

I can offer the option of a patch that fixes this problem. The person who
is responsible for supporting ssh has the discretion to take it as it is,
or can make own fix.

________________________________________________________________

--- xmerl-1.3.2/src/xmerl_xsd.erl 2013-10-26 14:25:25.000000000

+++ xmerl-1.3.2.1/src/xmerl_xsd.erl 2013-10-26 13:01:03.000000000

@@ -2799,12 +2799,16 @@

%%check_sequence(Seq,[],_Occ,_Env,_S,_Checked) ->

%%{error,{unmatched_elements,Seq}}.

  %% Choice one alternative must occur unless all alternatives are

%% optional or the entire choice is optional.

+%% EltexPatch: add skip xml comment

+check_choice([C = #xmlComment{} |Rest],CM,Env,Block,S,Checked) ->

+ check_choice(Rest,CM,Env,Block,S,[C |Checked]);

+

check_choice([T=#xmlText{}|Rest],Els,Occ,Env,S,Checked) ->

case is_whitespace(T) of

true ->

check_choice(Rest,Els,Occ,Env,S,[T|Checked]);

_ ->

{error,{error_path(T,undefined),?MODULE,

________________________________________________________________


 With best regards,

Malikov Constantin, software developer, Eltex.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20131030/7df429fa/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xml_comment.tar.gz
Type: application/x-gzip
Size: 27534 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20131030/7df429fa/attachment.bin>


More information about the erlang-bugs mailing list