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

htmlPrefilter() adds bogus element after self-closing tags #4191

martinml opened this Issue Oct 11, 2018 · 2 comments


None yet
3 participants
Copy link

martinml commented Oct 11, 2018

Being <x> any valid element, using htmlPrefilter() to parse a <br /> element inside an attribute of an <x> element adds a spurious </x> after it:

$.htmlPrefilter('<x foo="<br />"></x>');

This returns <x foo="<br ></x>"></x> (note the extra </x> inside the foo attribute).

I browsed other issues and I saw that a related one was marked as invalid because void elements must not have closing tags in HTML. This might be the same case, but the docs say that "[htmlPrefilter] will greedily ensure that all tags are XHTML-compliant", and I understand that <br /> is definitely valid XHTML (and this behavior ironically makes it invalid).

Is this a documentation thing, a bug (probably in the rxhtmlTag regex?) or am I missing something else?


This comment has been minimized.

Copy link

timmywil commented Oct 15, 2018

This issue and its workaround are documented here: jQuery.htmlPrefilter.

@timmywil timmywil closed this Oct 15, 2018


This comment has been minimized.

Copy link

gibson042 commented Oct 15, 2018

XHTML is built upon XML, and XML does not allow < in attribute values (as you can see in the W3C validator). It is valid HTML5, though, and you can employ the documented workaround if you need to process such input (or if the greediness of our default processing, which doesn't exempt attribute values, interferes with your data).

@lock lock bot locked as resolved and limited conversation to collaborators Apr 13, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.