Rhino parser does not accept E4X CDATA or PI literals

NEW
Unassigned

Status

Rhino
E4X
13 years ago
11 years ago

People

(Reporter: Igor Bukanov, Unassigned)

Tracking

(Blocks: 1 bug)

Dependency tree / graph
Bug Flags:
in-testsuite +

Details

(Reporter)

Description

13 years ago
Consider code like

var x = <![CDATA[ something ]]>;

This is a valid construction according to ECMA 357, 11.1.4 XML Initialiser:

XMLInitialiser :
        XMLMarkup
        XMLElement

where section 8.3 defines XMLMarkup as

XMLMarkup ::
     XMLComment
     XMLCDATA
     XMLPI

and 

XMLCDATA ::
     <![CDATA[ XMLCDATACharactersopt ]]>
XMLCDATACharacters ::
     SourceCharacters but no embedded sequence ]]>

Currently Rhino reports syntax error on this but simple change to the parser to
accept this triggers runtime error from XMLbeans library about missing document
root.

Which indicates 2 bugs: 

1. Bug in the parser

2. Bug in XML constructor since XML("<![CDATA[ something ]]>") is allowed.

Now the question was the real intention to allow standalone CDATA? If not, then
Rhino has only one bug.


There is related issue with XML comments and processing instructions which
similarly fail both in parser and the constructor. In addition there is subtle
incompatibility of E4X with SpiderMonkey/Rhino/JScript practice where "<!--" is
considered as comments until line end if "<!--" follows line end with optional
whitespace in between. But E4X requires that to indicate the start of real XML
comments which should last until -->, but that is another issue.
(Reporter)

Comment 1

13 years ago
CC Brendan and John for input
The ECMA-357 spec clearly says CDATA sections should be parsed as XMLMarkup.

> In addition there is subtle incompatibility of E4X with
> SpiderMonkey/Rhino/JScript practice where "<!--" is considered as comments
> until line end if "<!--" follows line end with optional whitespace in between.
> But E4X requires that to indicate the start of real XML comments which should
> last until -->, but that is another issue.

The way out, I think, is to do the "comment-hiding hack" for HTML only, or in
the case of SpiderMonkey, by default (for backward compatibility).  A new
runtime option, as well as compile-time configuration, is needed for E4X, and
can be enabled for XUL and other XML dialects.  Anyone wanting to use E4X from
HTML will have to use a distinguished script tag, perhaps via a
type="application/x-javascript;e4x" parameter.

/be
(Reporter)

Comment 3

13 years ago
(In reply to comment #2)
> The ECMA-357 spec clearly says CDATA sections should be parsed as XMLMarkup.

OK, then Rhino got 2 bugs. But then there is a problem in E4X specs:

Section 8.3, paragraph 4 states:

The left curly brace ({) and right curly brace (}) are used to delimit
expressions that may be embedded in tags or element content to dynamically
compute portions of the XML initialiser. The curly braces may appear in literal
form inside an attribute value, a CDATA, PI, or XML Comment. In all other cases,
the character reference &#x7B; must be used to represent the left curly brace
({) and the character reference &#x7D; must be used to represent the right curly
brace (}).

I read that {expr} is allowed inside CDATA (stand alone or embedded), but the
following grammar and grammar from 11.1.4 XML Initialiser tells the opposite: {}
should not be processed specially inside <!--, <![CDATA[ or <?. 

What is the intendent behaviour? Note also that instead of using &#x7D; {'}'}
can be used to escape the right curly brace and that would work inside CDATA as
well...




(Reporter)

Updated

13 years ago
Summary: Standalone <![CDATA[ .... ]]> should be allowed? → Standalone <![CDATA[ .... ]]> should be allowed
(Reporter)

Comment 4

13 years ago
Changing the title to better reflect bug's nature
Component: Core → E4X
Summary: Standalone <![CDATA[ .... ]]> should be allowed → Standalone <![CDATA[ .... ]]> or <?...> should be allowed
(Reporter)

Updated

13 years ago
Blocks: 270779
(Reporter)

Comment 5

13 years ago
*** Bug 287911 has been marked as a duplicate of this bug. ***
(Reporter)

Comment 6

13 years ago
*** Bug 287910 has been marked as a duplicate of this bug. ***
(Reporter)

Updated

13 years ago
Blocks: 287909

Comment 7

12 years ago
RCS file: /cvsroot/mozilla/js/tests/e4x/Expressions/11.4.1-01.js,v
done
Checking in 11.4.1-01.js;
/cvsroot/mozilla/js/tests/e4x/Expressions/11.4.1-01.js,v  <--  11.4.1-01.js
initial revision: 1.1
done
RCS file: /cvsroot/mozilla/js/tests/e4x/Expressions/11.4.1-02.js,v
done
Checking in 11.4.1-02.js;
/cvsroot/mozilla/js/tests/e4x/Expressions/11.4.1-02.js,v  <--  11.4.1-02.js
initial revision: 1.1
done
RCS file: /cvsroot/mozilla/js/tests/e4x/Expressions/11.4.1-03.js,v
done
Checking in 11.4.1-03.js;
/cvsroot/mozilla/js/tests/e4x/Expressions/11.4.1-03.js,v  <--  11.4.1-03.js
initial revision: 1.1
done
Flags: testcase+
(Reporter)

Comment 8

12 years ago
Reassigning to please_see_bug_288433@eml.cc pending resolution of bug 288433
Assignee: igor.bukanov → please_see_bug_288433
Assignee: please_see_bug_288433 → nobody

Comment 9

11 years ago
According to the test suite, spidermonkey has this same bug:

*-* Testcase e4x/Expressions/11.1.4-02.js failed:
Expected exit code 0, got 3
Testcase terminated with signal 0
Complete testcase output was:
./e4x/Expressions/11.1.4-02.js:48: SyntaxError: syntax error:
./e4x/Expressions/11.1.4-02.js:48: var cdataText = &lt;![CDATA[Kibology for all.&lt;br&gt;All for Kibology.]]&gt;;
./e4x/Expressions/11.1.4-02.js:48: ................^

Also, it seems like the error pointer for XML syntax errors just always points at the start of the XML.  Is that what it -should- do?

-- crowder

Comment 10

11 years ago
(In reply to comment #9)

this test passes in 1.8.0, 1.8, 1.9. Did you run the shell with -x to turn on e4x?

Comment 11

11 years ago
The jsDriver doesn't seem to run the test with the -x parameter for the shell, no...
The tests/e4x/shell.js should detect this.options (SpiderMonkey's options-setting native function) and call options('xml') if detected, in order to relieve testers from having to remember to use -o '-x' or whatever.

/be

Comment 13

11 years ago
(In reply to comment #12)
Checking in shell.js;
/cvsroot/mozilla/js/tests/e4x/shell.js,v  <--  shell.js
new revision: 1.9; previous revision: 1.8
done

Comment 14

11 years ago
(In reply to comment #13)

correctly detect and set xml

Checking in shell.js;
/cvsroot/mozilla/js/tests/e4x/shell.js,v  <--  shell.js
new revision: 1.10; previous revision: 1.9
done

Updated

11 years ago
Depends on: 368520

Updated

11 years ago
No longer blocks: 287909

Updated

11 years ago
Summary: Standalone <![CDATA[ .... ]]> or <?...> should be allowed → Rhino parser does not accept E4X CDATA or PI literals

Updated

11 years ago
Flags: in-testsuite+ → in-testsuite?

Updated

11 years ago
Flags: in-testsuite? → in-testsuite+
You need to log in before you can comment on or make changes to this bug.