Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javascript syntax error Firefox - demo.html #32

Open
GoogleCodeExporter opened this issue Nov 26, 2015 · 3 comments
Open

Javascript syntax error Firefox - demo.html #32

GoogleCodeExporter opened this issue Nov 26, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

Hi,

I tracked down a javascript syntax error in my application to x2js.

FIrefox 34.0.5
https://x2js.googlecode.com/hg/demo.html

- syntax error ... demo.html:1 
- the highlighted line in code is line 1:demo.html - <!doctype html>

The error is unhelpful and seems to point generally to a broken <script> tag. 
This is not the case in my application nor apparently on the demo page.

The demo page still works as expected but I feel it is worth taking note of.

I've searched project issues (keywords: syntax error firefox/firebug) but I 
don't see that this error has been previously reported.

Thanks for the project, it has made life easier having such a good library for 
converting xml<->json.

Kind regards,
Darryl

Original issue reported on code.google.com by darryljcousins on 18 Dec 2014 at 2:06

@GoogleCodeExporter
Copy link
Author

Hi, I have the same issue.
I was able to track it and found where it comes from. It seems that the firefox 
DOM parser does like this code:


try {
  parsererrorNS = parser.parseFromString("INVALID", "text/xml").childNodes[0].namespaceURI;
}
catch(err) {                    
  parsererrorNS = null;
}


When trying to parse the INVALID string, firefox DOM parser shows this "syntax 
error" on HTML line 1 in the console, event if the conversion error is 
surrounded by try-catch.

Original comment by [email protected] on 20 Feb 2015 at 7:37

@GoogleCodeExporter
Copy link
Author

Same here. Weird thing is that it works in Chrome perfectly. The XML seems also 
to be OK. But it always fails in Firefox within the try-catch block posted 
above.

Original comment by [email protected] on 27 Mar 2015 at 1:45

@GoogleCodeExporter
Copy link
Author

I think the code is trying to solve the fact that some browsers include the 
parsererror element in another namespace (eg: 
http://stackoverflow.com/questions/11563554/how-do-i-detect-xml-parsing-errors-w
hen-using-javascripts-domparser-in-a-cross).

It parses an invalid xml to get the possible namespace for the parsererror 
element.

What I think would be a better solution (altough I don't know if it will work 
for all browsers) is to eliminate this check and use a wildcard to get all 
parsererror elements independent of the namespace.

The patch below show the changes I have made and it has worked for me:

@@ -489,21 +489,9 @@
        var xmlDoc;
        if (window.DOMParser) {
            var parser=new window.DOMParser();          
-           var parsererrorNS = null;
-           // IE9+ now is here
-           if(!isIEParser) {
-               try {
-                   parsererrorNS = parser.parseFromString("<", 
"text/xml").childNodes[0].namespaceURI;
-                   console.log(parsererrorNS);
-               }
-               catch(err) {                    
-                   console.log('error:' + err);
-                   parsererrorNS = null;
-               }
-           }
            try {
                xmlDoc = parser.parseFromString( xmlDocStr, "text/xml" );
-               if( parsererrorNS!= null && xmlDoc.getElementsByTagNameNS(parsererrorNS, 
"parsererror").length > 0) {
+               if(xmlDoc.getElementsByTagNameNS("*", "parsererror").length > 0) {
                    //throw new Error('Error parsing XML: '+xmlDocStr);
                    xmlDoc = null;
                }

Original comment by [email protected] on 2 Jun 2015 at 10:27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant