Skip to content

Implement URLSearchParams.forEach() - #558

Merged
rbri merged 2 commits into
HtmlUnit:masterfrom
duonglaiquang:url_search_params
Mar 8, 2023
Merged

Implement URLSearchParams.forEach()#558
rbri merged 2 commits into
HtmlUnit:masterfrom
duonglaiquang:url_search_params

Conversation

@duonglaiquang

Copy link
Copy Markdown
Contributor

This PR:

  • Fixes to incorrect splitting by URLSeachParams when parameters contain url-encoded required characters like "&"
  • Adds an implementation of URLSeachParams.forEach()

FWIW, this was the code used to compare htmlunit vs Chrome behaviour of URLSeachParams's splitting. This PR fixes all the differences and I've rolled the important bits into the URLSeachParamsTest.appendSpecialChars() test.

<!DOCTYPE html>
<html>
<head>
<script>
var param = new URLSearchParams();
param.append("?x=1&", "foo");
param.append("bar", "http://foo.com/?x=1&y=2&z=3")
param.append("foobar", "baz")

// chrome: %3Fx%3D1%26=foo&bar=http%3A%2F%2Ffoo.com%2F%3Fx%3D1%26y%3D2%26z%3D3&foobar=baz
// htmlunit: x=1&=foo&bar=http%3A%2F%2Ffoo.com%2F%3Fx%3D1&y=2&z=3&foobar=baz
console.log(param.toString());

// chrome: true
// htmlunit: false
console.log(param.has("?x=1&"));

// chrome: http://foo.com/?x=1&y=2&z=3
// htmlunit: http://foo.com/?x=1
console.log(param.get("bar"));

param.set("foobar", "foo?bar&");

// chrome: foo?bar&
// htmlunit: foo?bar
console.log(param.get("foobar"));

param.delete("?x=1&");

// chrome: bar=http%3A%2F%2Ffoo.com%2F%3Fx%3D1%26y%3D2%26z%3D3&foobar=foo%3Fbar%26
// htmlunit: x=1&=foo&bar=http%3A%2F%2Ffoo.com%2F%3Fx%3D1&y=2&z=3&foobar=foo%3Fbar
console.log(param.toString());
</script>
</head>
<body>
</body>
</html>

@rbri
rbri merged commit bef420a into HtmlUnit:master Mar 8, 2023
@rbri

rbri commented Mar 8, 2023

Copy link
Copy Markdown
Member

Thanks a lot ❤️

if you find some time the only missing function for URLSearchParams is now sort() 😃

@duonglaiquang
duonglaiquang deleted the url_search_params branch March 8, 2023 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants