isaacs / sax-js

A sax style parser for JS
Other
1.09k stars 325 forks source link

Question on special character & with Angular build #223

Open bayy opened 6 years ago

bayy commented 6 years ago

I am using xml2js, which uses sax-js, to save and load a xml file to a server with Angular 5. I encountered a problem with char & in an angular production environment only.

I have a text field with value 'a & b', which is saved to the server as a & b using xml2js. When loading the data from the server, it works on a local environment. However, on a production server, it will complain that "Cannot read property 'toLowerCase' of undefined" with the following code.

this.parser.parseString(xmlSource, (err, result) => {
      allNodes = this.parseXML(result.x);
});

The err in the above code shows stack trace of minified code.

    TypeError: Cannot read property 'toLowerCase' of undefined
    at L (sax.js:913)
    at o.write (sax.js:1485)
    at h.parseString (parser.js:322)
    at h.parseString (parser.js:5)
    at e.fromXML (xml.service.ts:52)

line 912 of sax.js shows parser.entity returns null, though on local environment, it is 'amp'

screen shot 2018-01-12 at 4 33 58 pm

Any help will be greatly appreciated.

bayy commented 6 years ago

This turned out to be a bug in UglifyJS https://github.com/mishoo/UglifyJS2/issues/2783. It has been fixed.

vdechef commented 6 years ago

Thanks ! This helped me a lot. I had a problem with a Vue application that uses xlsx-populate. Webpack build was running without errors, but at runtime I had a ReferenceError in sax. Forcing uglifyjs-webpack-plugin to use the latest version of uglify-es solved my problem.