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

Test URL with Query string #101

Open
ssk910 opened this issue Nov 21, 2019 · 1 comment
Open

Test URL with Query string #101

ssk910 opened this issue Nov 21, 2019 · 1 comment
Labels

Comments

@ssk910
Copy link

ssk910 commented Nov 21, 2019

Occurred an Error

HTTP method : GET
URL : http://www.example.com?id=user1234&pw=!Q%40W%23E%24R&name=sghwang
Error msg : xhr-mock: No handler returned a response for the request.

(node:30976) UnhandledPromiseRejectionWarning: AssertionError: expected false to be true
    at Assertion.fail (C:\private\dev\java\enliple\rebuild\agent\mobon.ad.tracker.agent\node_modules\should\cjs
\should.js:275:17)
    at Assertion.value (C:\private\dev\java\enliple\rebuild\agent\mobon.ad.tracker.agent\node_modules\should\cj
s\should.js:356:19)
    at C:\private\dev\java\enliple\rebuild\agent\mobon.ad.tracker.agent\test\script\bdd\lib\ajax\AJAXer.spec.ts
:50:40
    at MockXMLHttpRequest.callbackListener [as onreadystatechange] (C:\private\dev\java\enliple\rebuild\agent\m
obon.ad.tracker.agent\script\lib\ajax\AJAXerCore.ts:211:11)
    at MockXMLHttpRequest.MockEventTarget.dispatchEvent (C:\private\dev\java\enliple\rebuild\agent\mobon.ad.tra
cker.agent\node_modules\xhr-mock\lib\MockEventTarget.js:43:20)
    at MockXMLHttpRequest.reportError (C:\private\dev\java\enliple\rebuild\agent\mobon.ad.tracker.agent\node_mo
dules\xhr-mock\lib\MockXMLHttpRequest.js:418:14)
    at MockXMLHttpRequest.handleError (C:\private\dev\java\enliple\rebuild\agent\mobon.ad.tracker.agent\node_mo
dules\xhr-mock\lib\MockXMLHttpRequest.js:537:14)
    at MockXMLHttpRequest.<anonymous> (C:\private\dev\java\enliple\rebuild\agent\mobon.ad.tracker.agent\node_mo
dules\xhr-mock\lib\MockXMLHttpRequest.js:388:30)
    at step (C:\private\dev\java\enliple\rebuild\agent\mobon.ad.tracker.agent\node_modules\xhr-mock\lib\MockXML
HttpRequest.js:50:23)
    at Object.throw (C:\private\dev\java\enliple\rebuild\agent\mobon.ad.tracker.agent\node_modules\xhr-mock\lib
\MockXMLHttpRequest.js:31:53)
    at rejected (C:\private\dev\java\enliple\rebuild\agent\mobon.ad.tracker.agent\node_modules\xhr-mock\lib\Moc
kXMLHttpRequest.js:23:65)


Passed without any errors

If I test with an URL which has a slash before question mark, It passed without any errors.

HTTP method : GET
URL : http://www.example.com/?id=user1234&pw=!Q%40W%23E%24R&name=sghwang


Conclusion

I searched on StackOverflow about this error.
It says xhr-mock compares the URLs by doing req.url().toString() === url
I think it's a bug.

@gflohr
Copy link

gflohr commented May 6, 2020

IMHO, this bug is just one aspect of a more general problem. The real XHR implementation normalizes all URL strings before the request is sent. Converting an empty path into a single slash is just one such normalization.

Likewise, default ports are stripped off, and the hostname part is normalized. For example, http://0177.0.0.1, http://0x7f.0.0.1, or http://0000177.0x0.0000.0x1 are different funny ways of writing http://127.0.0.1/, but a browser will treat them all in exactly the same manner. You can easily try it out by clicking the links.

So, why not just normalize all URLs for incoming requests with new URL(url).href? That would fix all of these problems. But, of course, it would introduce a small incompatibility with previous versions.

See http://www.guido-flohr.net/the-gory-details-of-url-validation/ for more such details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants