mozilla / rhino

Rhino is an open-source implementation of JavaScript written entirely in Java
https://rhino.github.io
Other
4.17k stars 845 forks source link

Some XML parsing is not supported #463

Open wangchaoyuwangchaoyu opened 6 years ago

wangchaoyuwangchaoyu commented 6 years ago

Node Code Snippet :

render() {
    let clazz = this.state.collapse ? 'fa fa-minus-square-o' : 'fa fa-plus-square-o';
    return (
      <div className='repl-cljs-doc'>
        {
          <span className='repl-cljs-doc-list'>
            <i className={clazz} onClick={this.onToggleCollapse}></i>
            <span className='doc-header'>{this.props.name}</span>
            {
              this.state.collapse
                ? <div className='doc-body'>
                    <span className='doc-definition' dangerouslySetInnerHTML={{__html:this.props.definition}}></span>
                    <div className='doc-description'>
                      {this.props.description}
                    </div>
                  </div>
                : null
            }
          </span>
        }
      </div>
    );
  }

If have '{}' in XML ,it cannot be parsing correctly.

p-bakker commented 2 years ago

I know its been a while since you've filed this issue, but I wonder how the code above is a NodeJS code snippet, because to my knowledge NodeJS never supported E4x and the code snippet above definetly is E4X syntax, so not valid plain JavaScript.

Or might you have used https://www.npmjs.com/package/babel-plugin-transform-simple-e4x?

p-bakker commented 2 years ago

This is a bug though: <div><span></span></div> works, <div>{new XML('<span></span>')}</div> works, but <div>{<span></span>}</div> doesnt.

Problem lies in the call to TokenStream.getFirstXMLToken() in Parser.xmlInitializer(): .getFirstXMLToken() resets TokenStream.xmlOpenTagsCount to 0, which messes stuff up: the Rhino code doesn't account for nested XML literals, which is what is happening in <div>{<span></span>}</div>, where <span></span> is a nested XML literal within an epression in the outer XML literal