-
Notifications
You must be signed in to change notification settings - Fork 20.6k
$.parseHTML() creates anchor elements with empty href property in 1.12/2.2 in Chrome #2941
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
Comments
The result of Do you have code that depends on stringifying DOM elements as you do in the example? |
Closing as worksforme. Please provide a test case to reopen. |
I checked the code in Firefox 44, IE 11 and Chrome 48 |
@vmagik Thanks for the update, we had an impression this report is about stringifying DOM elements but it seems the href property is, indeed, set to an empty string in Chrome. We need to investigate further. |
OK, I nailed down the issue to commit 58c2460. Here's a non-jQuery test case: var doc = document.implementation.createHTMLDocument();
var div = doc.createElement('div')
div.innerHTML = '<a href="foo.html"></a>';
document.body.innerHTML = 'URL: ' + div.childNodes[0].href; Also posted at https://jsfiddle.net/ebacz2u5/2/. This test case fails in Chrome 48 and succeeds in Firefox 44, Safari 9.0, Edge 13, IE 9-11 (all that support I see it reported upstream at https://bugs.chromium.org/p/chromium/issues/detail?id=568886 |
@vmagik How are you using this code in your real application? Are you calling |
I call $.parseHTML() myself. |
What are you doing with the result though? Again we're trying to determine the seriousness of the bug based on the way things are being used in real code. |
I open a window to show resulting href. Also can use it for ajax call |
You mean to show it to the user? I'm trying to get a sense of the work flow that is occurring here. Some type of HTML is parsed, where does it come from? Why is the href shown in a window? |
I show it to the user. |
I guess if there's no workaround, we'll need to back out |
Start with removal in 1.12.2/2.2.2. We're going to wait on removing in 3.0. |
This seems to be fixable by something as simple as var base = createdDoc.head.appendChild( createdDoc.createElement( "base" ) );
base.href = document.location.href; Dirty, but not the first time we've had to spackle over browser behavior. |
@gibson042 Nice! |
Since the caller can pass in a I still would suggest we back this out in 1.x/2.x because we aren't using it consistently and it's not documented. |
I like where @gibson042's going and I'd like to experiment with it on |
Just saw this from the Chromium bugtracker. Interesting that it's affecting a larger library. @vmagik - are you sure you're getting the resolved URL in Firefox? Your JSBin link shows just @gibson042's fix looks like the correct way to go about it. Based on the brief look I had at the specs, the default base URL is |
The document.implementation.createHTMLDocument("") method creates inert documents which is good but using it has introduced issues around anchor elements href property not resolving according to the current document. Because of that, this patch is getting backed out on 1.x/2.x branches. Refs cfe468f Refs gh-1505 Fixes gh-2941
The document.implementation.createHTMLDocument("") method creates inert documents which is good but using it has introduced issues around anchor elements href property not resolving according to the current document. Because of that, this patch is getting backed out on 1.x/2.x branches. (cherry-picked from c5c3073) Refs cfe468f Refs gh-1505 Fixes gh-2941
@Elusive138 Yes, Firefox 44 shows just "test.html" with jQuery 1.12.x. But with jQuery 1.11.3 it shows resolved URL. |
$.parseHTML() seems to be broken in jQuery v1.12.0 and later for Chrome
This code shows empty string in Chrome but it is "test.html" in other browsers.
In jQuery 1.11.3 Chrome was OK too.
EDIT (@mgol): I modified the
alert
to alert thehref
property of the anchor element; originally the test case was alerting the element (alert(ref)
) which meant it relied on its stringification.The text was updated successfully, but these errors were encountered: