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

make sure href setter throws if invalid #3176

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/workerd/api/url-standard.c++
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ kj::ArrayPtr<const char> URL::getHref() {
return inner.getHref();
}

void URL::setHref(kj::String value) {
inner.setHref(value);
void URL::setHref(jsg::Lock& js, kj::String value) {
// Href setter is the only place in URL parser that is allowed to throw except the constructor.
if (!inner.setHref(value)) {
auto context = jsg::TypeErrorContext::setterArgument(typeid(URL), "href");
jsg::throwTypeError(js.v8Isolate, context, "valid URL string");
}
KJ_IF_SOME(searchParams, maybeSearchParams) {
searchParams->reset();
}
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/api/url-standard.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class URL: public jsg::Object {
}

kj::ArrayPtr<const char> getHref();
void setHref(kj::String value);
void setHref(jsg::Lock& js, kj::String value);

kj::Array<const char> getOrigin();

Expand Down
1 change: 0 additions & 1 deletion src/workerd/api/wpt/url-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const idnaTestV2Window = run('IdnaTestV2.window.js');
export const historical = run('historical.any.js', {
expectedFailures: [
'Constructor only takes strings',
"Setting URL's href attribute and base URLs",
'URL: no structured serialize/deserialize support',
'URLSearchParams: no structured serialize/deserialize support',
],
Expand Down
19 changes: 15 additions & 4 deletions src/wpt/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ globalThis.fetch = async (url) => {
};
};

globalThis.GLOBAL = { isWindow: () => false };
globalThis.self = globalThis;
globalThis.GLOBAL = {
isWindow() {
return false;
},
};

globalThis.done = () => undefined;

Expand Down Expand Up @@ -303,16 +308,22 @@ function sanitizeMessage(message) {
);
}

async function validate(options) {
function validate(testFileName, options) {
const expectedFailures = new Set(options.expectedFailures ?? []);

let failing = false;
for (const err of globalThis.errors) {
if (!expectedFailures.delete(err.message)) {
err.message = sanitizeMessage(err.message);
throw err;
console.error(err);
failing = true;
}
}

if (failing) {
throw new Error(`${testFileName} failed`);
}

if (expectedFailures.size > 0) {
console.info('Expected failures', expectedFailures);
throw new Error(
Expand All @@ -326,7 +337,7 @@ export function run(file, options = {}) {
async test() {
prepare(options);
await import(file);
await validate(options);
validate(file, options);
},
};
}