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 new URLSearchParams constructor features #4523

Merged
merged 3 commits into from
Jan 12, 2017

Conversation

annevk
Copy link
Member

@annevk annevk commented Jan 11, 2017

The main thing here is new tests for
whatwg/url#175 but I also found issues
with some existing tests that I’m attempting to fix at the same time.

The current tests assumed the constructor argument was mandatory, but
it’s in fact optional. The other issue was that the current test assume
stringifying DOMException.prototype throws, but I don’t think that’s
the case.

The main thing here is new tests for
https://github.com/whatwg/url/pull/175/files but I also found issues
with some existing tests that I’m attempting to fix at the same time.

The current tests assumed the constructor argument was mandatory, but
it’s in fact optional. The other issue was that the current test assume
stringifying DOMException.prototype throws, but I don’t think that’s
the case.
@wpt-pr-bot
Copy link
Collaborator

@wpt-stability-bot
Copy link

wpt-stability-bot commented Jan 11, 2017

Chrome

Testing revision df3a098
Starting 10 test iterations
All results were stable

All results

/url/urlsearchparams-constructor.html
Subtest Results
OK
Custom [Symbol.iterator] FAIL
URLSearchParams constructor, {} as argument FAIL
Parse space PASS
Parse + PASS
URLSearchParams constructor, no arguments PASS
Parse 💩 PASS
URLSearchParams constructor, empty string as argument PASS
Parse %00 PASS
Parse %f0%9f%92%a9 PASS
URLSearchParams constructor, string. PASS
Parse %e2%8e%84 PASS
Basic URLSearchParams construction PASS
Parse ⎄ PASS
Construct with array with two keys FAIL
Parse %20 PASS
URLSearchParams constructor, DOMException.prototype as argument FAIL
Construct with object with + FAIL
Parse \0 PASS
Construct with object with two keys FAIL
URLSearchParams constructor, object. PASS

@wpt-stability-bot
Copy link

wpt-stability-bot commented Jan 11, 2017

Firefox

Testing revision df3a098
Starting 10 test iterations
All results were stable

All results

/url/urlsearchparams-constructor.html
Subtest Results
OK
Custom [Symbol.iterator] FAIL
URLSearchParams constructor, {} as argument FAIL
Parse space PASS
Parse + PASS
URLSearchParams constructor, no arguments PASS
Parse 💩 PASS
URLSearchParams constructor, empty string as argument PASS
Parse %00 PASS
Parse %f0%9f%92%a9 PASS
URLSearchParams constructor, string. PASS
Parse %e2%8e%84 PASS
Basic URLSearchParams construction PASS
Parse ⎄ PASS
Construct with array with two keys FAIL
Parse %20 PASS
URLSearchParams constructor, DOMException.prototype as argument PASS
Construct with object with + FAIL
Parse \0 PASS
Construct with object with two keys FAIL
URLSearchParams constructor, object. PASS

assert_true(params != null, 'constructor returned non-null value.');
assert_equals(params.__proto__, URLSearchParams.prototype, 'expected URLSearchParams.prototype as prototype.');
params = new URLSearchParams({});
assert_equals(params + '', '%5Bobject+Object%5D=');
}, 'URLSearchParams constructor, empty.');
}, 'URLSearchParams constructor, empty and unusual input.');
Copy link
Member

Choose a reason for hiding this comment

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

Separate tests per input will make failures clearer.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done this as well.

let params3 = new URLSearchParams(params2)
assert_equals(params3.get("a"), params1.get("a"))
assert_equals(params3.get("a"), "b")
}, "Evil constructor test")
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this works as expected. params1[Symbol.iterator] === params2[Symbol.iterator] === URLSearchParams.prototype[Symbol.iterator]. The assignment is a no-op. The iterator will look up the private data on the instance it's invoked on, so iterating over params2 will always give no params, so params3 should be empty.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, shit. I based that on #4240 which I also wrote. How would I create a custom iterator? Would assigning an array be sufficient?

Copy link
Member

Choose a reason for hiding this comment

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

The easiest way is to use a generator:

params3[Symbol.iterator] = function *() {
  yield [a, b];
  yield [c, d];
};

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, used.

annevk added a commit that referenced this pull request Jan 11, 2017
Per feedback in #4523 the original test would never be able to pass.
jdm pushed a commit that referenced this pull request Jan 11, 2017
Per feedback in #4523 the original test would never be able to pass.
assert_true(params != null, 'constructor returned non-null value.');
assert_equals(params.__proto__, URLSearchParams.prototype, 'expected URLSearchParams.prototype as prototype.');
}, "URLSearchParams constructor, empty string as argument")

test(() => {
params = new URLSearchParams({});
assert_equals(params + '', '%5Bobject+Object%5D=');
Copy link
Member

Choose a reason for hiding this comment

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

I think this should now be equivalent to no arguments per record semantics. So just empty string.

}
let params2 = new URLSearchParams(params)
assert_equals(params2.get("a"), "b")
}, "Evil constructor test")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe "overridden iterator test" is now more accurate.

@annevk
Copy link
Member Author

annevk commented Jan 12, 2017

Thanks!

@annevk annevk merged commit 74a75c9 into master Jan 12, 2017
@annevk annevk deleted the annevk/urlsearchparams-constructor branch January 12, 2017 16:12
annevk added a commit to whatwg/url that referenced this pull request Jan 12, 2017

test(() => {
params = new URLSearchParams(DOMException.prototype);
assert_equals(params.toString(), "Error=")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you clarify why this is the expected result here. My interpretation of the Web IDL spec [1] is that we should go to step 11.1 and treat the input as a sequence (not a String).

[1] https://heycam.github.io/webidl/#es-union

Copy link
Member

Choose a reason for hiding this comment

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

Yes but method is undefined so it then continues on with the rest of the steps.

Copy link
Contributor

Choose a reason for hiding this comment

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

How about 11.4 ? We do have a record in there.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah you're right. I think this is indeed incorrect.

Copy link
Member Author

Choose a reason for hiding this comment

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

#4581 has the fix. I also commented on the WebKit bug.

@@ -124,6 +134,30 @@
params = new URLSearchParams('a%f0%9f%92%a9b=c');
assert_equals(params.get('a\uD83D\uDCA9b'), 'c');
}, 'Parse %f0%9f%92%a9'); // Unicode Character 'PILE OF POO' (U+1F4A9)

;[
{ "input": {"+": "%C2"}, "output": [[" ", "\uFFFD"]], "name": "object with +" },
Copy link
Member

Choose a reason for hiding this comment

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

@annevk, I'm in the process of implementing the URL spec change in Node.js. Where does it say in the URL Standard that keys and values of a record must be unescaped?

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's a good question, it doesn't and I'm not sure it should. I filed whatwg/url#220.

TimothyGu added a commit to TimothyGu/node that referenced this pull request Jan 28, 2017
TimothyGu added a commit to nodejs/node that referenced this pull request Feb 1, 2017
PR-URL: #11060
Fixes: #10635
Ref: whatwg/url#175
Ref: web-platform-tests/wpt#4523
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Feb 2, 2017
PR-URL: nodejs#11060
Fixes: nodejs#10635
Ref: whatwg/url#175
Ref: web-platform-tests/wpt#4523
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants