Dont emit message from DOMParser parseFromString
Categories
(Core :: XML, task)
Tracking
()
People
(Reporter: mozilla, Unassigned)
Details
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:67.0) Gecko/20100101 Firefox/67.0
Steps to reproduce:
In console, execute:
try {new DOMParser().parseFromString('INVALID', 'text/xml');} catch (e) {}
or
try {new DOMParser().parseFromString('', 'text/xml');} catch (e) {}
Actual results:
Both print errors:
XML Parsing Error: syntax error
or
XML Parsing Error: no root element found
Expected results:
No error should be printed, due to the try/catch.
Updated•6 years ago
|
Comment 1•6 years ago
|
||
Hello Neil,
So I'm not sure there's a bug.
Parse str using a parser that matches type's supported MIME types (either XML or HTML), and return a Document object contained the parsed content if successful. If not successful, returns a Document describing the error.
You can check that by evaluating the following:
x = (new DOMParser()).parseFromString('INVALID', 'text/xml');
console.log("parsed string:", x);
The console.log call is executed (i.e. parseFromString didn't throw), and print a XmlDocument that you can inspect.
(you can also check on Chrome, which has the same behavior)
Then Firefox emit an error message to warn you that something unexpected happened.
Does that make sense?
Updated•6 years ago
|
The problem is with this part:
Then Firefox emit an error message to warn you that something unexpected happened.
I don't want the console populated with the error. I have some code which is purposely parsing xml with an error in it for the purpose of getting the error namespace (which changes from browser to browser). The console warning is not desirable and makes my users think there's an error in my application. Other browsers do not output the error to the console. If the console output is viewed as desirable, there should at least be a way to prevent it when the parsing error is expected and/or handled.
Comment 3•5 years ago
|
||
This is the code responsible for logging the warning: https://searchfox.org/mozilla-central/rev/23dd7c485a6525bb3a974abeaafaf34bfb43d76b/parser/htmlparser/nsExpatDriver.cpp#705-722
I'll leave it to the Core:XML owner to decide what we should do with it.
Updated•5 years ago
|
Updated•3 years ago
|
Description
•