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

feat(node/_error): Implement ERR_INVALID_URL_SCHEME #1355

Merged
merged 6 commits into from
Oct 7, 2021
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
14 changes: 13 additions & 1 deletion node/_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/** ********** NOT IMPLEMENTED
* ERR_INVALID_MODULE_SPECIFIER
* ERR_INVALID_PACKAGE_TARGET
* ERR_INVALID_URL_SCHEME
* ERR_MANIFEST_ASSERT_INTEGRITY
* ERR_MODULE_NOT_FOUND
* ERR_PACKAGE_PATH_NOT_EXPORTED
Expand Down Expand Up @@ -2395,3 +2394,16 @@ export class ERR_INVALID_URL extends NodeTypeError {
this.input = input;
}
}

export class ERR_INVALID_URL_SCHEME extends NodeTypeError {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

constructor(expected: string | [string] | [string, string]) {
expected = Array.isArray(expected) ? expected : [expected];
const res = expected.length === 2
? `one of scheme ${expected[0]} or ${expected[1]}`
: `of scheme ${expected[0]}`;
super(
"ERR_INVALID_URL_SCHEME",
`The URL must be ${res}`,
);
}
}
3 changes: 1 addition & 2 deletions node/_tools/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
],
"parallel": [
"test-assert-async.js",
"test-assert.js",
"test-url-fileurltopath.js"
Copy link
Member

Choose a reason for hiding this comment

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

Great!

"test-assert.js"
]
},
"tests": {
Expand Down
9 changes: 4 additions & 5 deletions node/_tools/suites/parallel/test-url-fileurltopath.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ function testInvalidArgs(...args) {
// Input must be string or URL
testInvalidArgs(null, undefined, 1, {}, true);

// TODO(wafuwafu13): implement ERR_INVALID_URL_SCHEME
// // Input must be a file URL
// assert.throws(() => url.fileURLToPath('https://a/b/c'), {
// code: 'ERR_INVALID_URL_SCHEME'
// });
// Input must be a file URL
assert.throws(() => url.fileURLToPath('https://a/b/c'), {
code: 'ERR_INVALID_URL_SCHEME'
});

{
const withHost = new URL('file://host/a');
Expand Down
3 changes: 2 additions & 1 deletion node/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_FILE_URL_HOST,
ERR_INVALID_FILE_URL_PATH,
ERR_INVALID_URL_SCHEME,
} from "./_errors.ts";
import {
CHAR_BACKWARD_SLASH,
Expand Down Expand Up @@ -53,7 +54,7 @@ export function fileURLToPath(path: string | URL): string {
throw new ERR_INVALID_ARG_TYPE("path", ["string", "URL"], path);
}
if (path.protocol !== "file:") {
throw new Deno.errors.InvalidData("invalid url scheme");
throw new ERR_INVALID_URL_SCHEME("file");
}
return isWindows ? getPathFromURLWin(path) : getPathFromURLPosix(path);
}
Expand Down
2 changes: 0 additions & 2 deletions node/url_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Deno.test({
},
});

// todo(wafuwafu13) Add Windows and invalid case
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Related: #1335 (review)


Deno.test({
ignore: isWindows,
name: "fileURLToPath",
Expand Down