🌐 AI搜索 & 代理 主页
Skip to content

Conversation

@mgol
Copy link
Member

@mgol mgol commented Mar 30, 2015

IE throws an error on cross-domain PATCH requests if issued via the ActiveX
interface. This commit switches the logic to use the native XHR in all
non-local requests.

Fixes gh-1684

I'd like to test it but we'd need a real cross-domain request that has Access-Control-Allow-Origin set to * and will respond to PATCH requests. Can we have a page like that? cc @gnarf @ryanneufeld @aulvi

src/ajax/xhr.js Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look like a ua sniff, is that a really best way to do this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a browser sniff, not UA sniff (changes in UA won't make this code behave differently). Also, this will not catch any new browsers but only old, specific ones (i.e. only IE8 or newer IE in IE8 document mode) so this will not have any unwanted effect on new browsers.

But if you have any idea how to test for this specific issue, I'm listening. :) I just don't think it's possible to test for such weird cases in JS code, especially without seriously impacting performance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I think we'd all prefer feature tests, but we've resigned ourselves to do this in a few necessary places. This one seems legit.

mgol added a commit to mgol/jquery that referenced this pull request Apr 7, 2015
IE throws an error on cross-domain PATCH requests if issued via the ActiveX
interface. This commit switches the logic to use the native XHR in all
non-local requests.

Fixes jquerygh-1684
Closes jquerygh-2183
src/ajax/xhr.js Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all got quite convoluted. How about reversing the polarity?

// Native XHR cannot access local files, always use ActiveX for that case
return this.isLocal ||

    // Also force ActiveX for non-RFC2616 methods with IE<9 (trac-13240)
    // http://msdn.microsoft.com/en-us/library/ie/ms536648(v=vs.85).aspx
    // ...but *ONLY* IE<9, since IE 10-11 cross-domain PATCH requires native XHR (gh-1684)
    document.documentMode < 9 && !/^(?:get|post|head|put|delete|options)$/i.test( this.type ) ?

    createActiveXHR() :
    createStandardXHR() || createActiveXHR();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems more readable but what's the point of the last || createActiveXHR() in your example?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're talking about this, how about simple if or else here and there, ternaries might not be a good choice for conditions like this.

It shouldn't hit bytes count too much or not at all

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we specifically tests for "patch"?

( document.documentMode < 9 && /^patch$/i.test( this.type ) || createStandardXHR() ) && createActiveXHR();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

( document.documentMode < 9 && /^patch$/i.test( this.type ) || createStandardXHR() ) && createActiveXHR();

IE<9 doesn't support any non-RFC2616 method as indicated in the comment. I don't think testing for PATCH is enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with the document.documentMode check. Depending on when 3.0 ships I am starting to think we might just want to patch the 1.x line and not even have a compat branch, since we will drop it soon thereafter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhoh, can of worms opened.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But for now, I think it's best to stick with the solution we have.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only let's have an couple if here not ternary with || and && abomination

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I'll modify the patch.

mgol added a commit to mgol/jquery that referenced this pull request Apr 26, 2015
IE throws an error on cross-domain PATCH requests if issued via the ActiveX
interface. This commit switches the logic to use the native XHR in all
non-local requests.

Fixes jquerygh-1684
Closes jquerygh-2183
mgol added a commit to mgol/jquery that referenced this pull request Apr 26, 2015
IE throws an error on cross-domain PATCH requests if issued via the ActiveX
interface. This commit switches the logic to use the native XHR in all
non-local requests.

Fixes jquerygh-1684
Closes jquerygh-2183
@mgol
Copy link
Member Author

mgol commented Apr 26, 2015

PR updated, a test added thanks to http://httpbin.org/ (thanks @tomchentw for the suggestion!). Unfortunately, if we want to have it tested we have to have working PATCH support on TestSwarm and it seems it got broken on BrowserStack again. I confirmed locally on IE10 & IE11 that the test fails on current compat & passes with my patch but it fails on BrowserStack in both cases.

We already have one PATCH test that's blacklisted on TestSwarm everywhere except IE8. We could blacklist this one as well but it tests a bug in IE10-11 so I'd rather have them tested. In fact, I'd like to make the previous test run in all IE versions since the ajaxSettings.xhr fallback logic is pretty complicated.

Can anyone reach to BrowserStack so that they really solve this issue so that it doesn't re-occur constantly? @jzaefferer?

mgol added a commit to mgol/jquery that referenced this pull request Apr 26, 2015
IE throws an error on cross-domain PATCH requests if issued via the ActiveX
interface. This commit switches the logic to use the native XHR in all
non-local requests.

Fixes jquerygh-1684
Closes jquerygh-2183
mgol added a commit to mgol/jquery that referenced this pull request Apr 26, 2015
IE throws an error on cross-domain PATCH requests if issued via the ActiveX
interface. This commit switches the logic to use the native XHR in all
non-local requests.

Fixes jquerygh-1684
Closes jquerygh-2183
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So now we need a internet connection to run the tests and rely on the third party?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test requires a real cross-domain PATCH request. So it's either internet connection required or a separate server set up locally (which most people won't do, it's an additional hassle) that responds to PATCH requests and sends CORS headers.

Apart from using a 3rd party service we may define a separate domain with a new nginx config just for this test. @gnarf doesn't have time to work on it now and even if I sent him an nginx config for this new server, this would still be the only externally visible server with CORS enabled that's responding to cross-domain requests. This is a security risk so it would have to be done carefully; that's why @gnarf suggested to use an external service.

Do you have any other ideas?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best way would be to run http-server, but until we have php-dep with swarm we can't do it.

I'd say stubbing is another option to consider, i remember we talked about introducing these kind of testing for special cases, it will also resolve your browserstack issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way would be to test jQuery.ajaxSettings.xhr, not the whole ajax call.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you test jQuery.ajaxSettings.xhr? And what stubbing do you propose? You cannot test if a native API bugs is worked around properly if you replace those native APIs with stubs that won't reproduce these bugs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same exact thing you could do with stubbing interface without introducing concerns above.

So what do you propose? To add a couple of stubs that represent IE8 (no cross-domain support, PATCH only via ActiveX) and IE10-11 (cross-domain PATCH only via native XHR) and test them? IMO it's incredibly hard to create such stubs and be sure everything is replicated properly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could try, i'm fine with landing it as is, afterwards, i could try to do this myself if you found this to hard.

Would like others to agree with my view though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i could try to do this myself if you found this to hard.

It's not hard to implement (just a little tedious), it's hard to be sure the whole behavior is replicated properly. Especially that IE11 up until recently was receiving more substantial patches so sth like that could have changed behind us and we wouldn't detect it if we just tested on stubs. Maybe now that's not an issue (@dmethvin probably know more) but I still feel uneasy about not testing this on real browsers instead of just our assumptions about how they work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, Spartan will have just about all the IE-isms removed. So it should be safe to use .documentMode because Spartan won't even have document modes.

Also, a detection via if ( window.ActiveXObject ) { ... } fails in IE11 because it was used for bad browser sniffs. You could use it to your advantage in this case perhaps? Actually I guess not because IE10 should use the native XHR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, a detection via if ( window.ActiveXObject ) { ... } fails in IE11 because it was used for bad browser sniffs.

window.ActiveXObject !== undefined will succeed, though since we use it ourselves. ;) But this would be stepping over our implementation, document.documentMode seems safer here.

@timmywil timmywil modified the milestones: 1.11.3/2.1.4, 3.0.0 May 4, 2015
@timmywil
Copy link
Member

timmywil commented May 4, 2015

In the meeting, we discussed the possibility of separating the integration test from our unit tests. I proposed this because I do agree that it's best that the unit tests do not require an internet connection. However, the test in this PR is worthwhile. So, I'd say place this test on a page that can be tested independently of the unit tests and we can at least run it before releases. In the future, I'd like to see more integration testing (specifically, to replace all of our mock mouse clicks and such in events).

mgol added a commit to mgol/jquery that referenced this pull request May 11, 2015
IE throws an error on cross-domain PATCH requests if issued via the ActiveX
interface. This commit switches the logic to use the native XHR in all
non-local requests.

Fixes jquerygh-1684
Closes jquerygh-2183
IE throws an error on cross-domain PATCH requests if issued via the ActiveX
interface. This commit switches the logic to use the native XHR in all
non-local requests.

Fixes jquerygh-1684
Closes jquerygh-2183
@mgol
Copy link
Member Author

mgol commented May 11, 2015

PR updated. This is how the page looks like in IE11:

Before applying the patch:
screen shot 2015-05-11 at 19 24 24

After applying the patch:
screen shot 2015-05-11 at 19 23 58

If no one opposes, I'll merge it soon.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this change. We do have special logic for all IE versions now but PATCH is broken again on BrowserStack in some IEs. Removing it completely sounds dangerous, though until we have integration tests in place.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: this wasn't working for me as I have the extension installed and then in the Live interface PATCH is not supported. It should work fine on our TestSwarm testing

@markelog
Copy link
Member

LGTM

@mgol mgol removed the Needs review label May 18, 2015
mgol added a commit that referenced this pull request May 18, 2015
IE throws an error on cross-domain PATCH requests if issued via the ActiveX
interface. This commit switches the logic to use the native XHR in all
non-local requests.

Fixes gh-1684
Closes gh-2183
@mgol
Copy link
Member Author

mgol commented May 18, 2015

Landed at 61f812b.

@mgol mgol closed this May 18, 2015
@mgol mgol deleted the cors-activex branch May 18, 2015 20:26
@mgol mgol removed this from the 3.0.0 milestone Nov 9, 2015
@mgol
Copy link
Member Author

mgol commented Nov 9, 2015

Removing the milestone since it's already on the issue and it should stay there.

e00dan pushed a commit to e00dan/jquery that referenced this pull request Oct 7, 2016
IE throws an error on cross-domain PATCH requests if issued via the ActiveX
interface. This commit switches the logic to use the native XHR in all
non-local requests.

Fixes jquerygh-1684
Closes jquerygh-2183
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Development

Successfully merging this pull request may close these issues.

7 participants