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

.html method does not give a warning when dropping malformed tags #1718

Closed
ShadSterling opened this issue Oct 17, 2014 · 8 comments
Closed

Comments

@ShadSterling
Copy link

if you call $("#someid").html( htmlString ) when htmlString contains malformed tags, the malformed
tags are silently dropped.

For example, http://jsbin.com/bucik/1/edit?html,console,output

This should not be silent, a warning should be logged.

@dmethvin
Copy link
Member

Our HTML parser is the browser's parser. Does it act differently, for example throw an exception, when you do not use jQuery and instead use direct DOM operations?

@ShadSterling
Copy link
Author

I'm not familiar with the direct DOM operations, what would be equivalent? Using document.getElementById("someid").innerHTML = htmlString, it does not act differently in Firefox, Chromium, Safari, or Opera; see http://jsbin.com/hobuze/edit?html,console,output

If this is a browser bug, why is it the same in multiple browsers?

@dmethvin
Copy link
Member

Yes, that is the equivalent operation, and the two behave similarly. No browser attempts to give an error, they just try to make sense of what you have given them. which may involve ignoring some of the input. See this article.

@ShadSterling
Copy link
Author

I understand dropping some of the input, but preventing developers from seeing the problem is an impediment to debugging. If the browsers fix the bug in their innerHTML= implementations, will that also generate the warning on .html()?

https://bugzilla.mozilla.org/show_bug.cgi?id=1085368
https://code.google.com/p/chromium/issues/detail?id=425101
https://bugs.webkit.org/show_bug.cgi?id=137881

@dmethvin
Copy link
Member

Per the article, HTML5 parsing is lenient by design. A browser can give something like a console warning, but jQuery doesn't get involved in that process--you would need to look at the console.. IE10 and IE11 already do this for many static HTML errors on page, but don't give errors on HTML injection via .innerHTML.
capture

@ShadSterling
Copy link
Author

A console warning is exactly what I think is missing.

@mgol
Copy link
Member

mgol commented Oct 20, 2014

@Polyergic I don't think it's jQuery's job to provide console warnings for such things; browsers would have it easy to implement them today and they're not doing it on purpose; otherwise devs would get flooded with warnings.

jQuery's .html() setter internally sets the value of innerHTML so if a browser generates the warning, using jQuery will do it too. If we claimed we know better than browser vendors and there should be warnings about that, if a browser implements its own warnings you'd get a duplicate.

We're doing a right thing by not logging anything here by ourselves.

@ShadSterling
Copy link
Author

... which is why I submitted bugs to the browsers...

@lock lock bot locked as resolved and limited conversation to collaborators Jun 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants