Skip to content

Commit 93d0beb

Browse files
jasnelltargos
authored andcommitted
src,test: expand test coverage for urlpattern and fix error
PR-URL: #56878 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
1 parent edb194b commit 93d0beb

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

src/node_url_pattern.cc

+5-3
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,14 @@ URLPatternRegexProvider::regex_search(std::string_view input,
104104
return std::nullopt;
105105
}
106106

107+
// V8 checks that the regexp exec result is one of the correct types.
108+
DCHECK_IMPLIES(!entry->IsUndefined(), entry->IsString());
109+
107110
if (entry->IsUndefined()) {
108111
result.emplace_back(std::nullopt);
109112
} else if (entry->IsString()) {
110113
Utf8Value utf8_entry(isolate, entry.As<String>());
111114
result.emplace_back(utf8_entry.ToString());
112-
} else {
113-
UNREACHABLE("v8::RegExp::Exec return a non-string, non-undefined value.");
114115
}
115116
}
116117
return result;
@@ -191,7 +192,8 @@ void URLPattern::New(const FunctionCallbackInfo<Value>& args) {
191192
return;
192193
}
193194
} else {
194-
THROW_ERR_MISSING_ARGS(env, "baseURL or options must be provided");
195+
THROW_ERR_INVALID_ARG_TYPE(env,
196+
"second argument must be a string or object");
195197
return;
196198
}
197199

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
const { URLPattern } = require('url');
6+
const { throws } = require('assert');
7+
8+
// Verifies that calling URLPattern with no new keyword throws.
9+
throws(() => URLPattern(), {
10+
code: 'ERR_CONSTRUCT_CALL_REQUIRED',
11+
});
12+
13+
// Verifies that type checks are performed on the arguments.
14+
throws(() => new URLPattern(1), {
15+
code: 'ERR_INVALID_ARG_TYPE',
16+
});
17+
18+
throws(() => new URLPattern({}, 1), {
19+
code: 'ERR_INVALID_ARG_TYPE',
20+
});
21+
22+
throws(() => new URLPattern({}, '', 1), {
23+
code: 'ERR_INVALID_ARG_TYPE',
24+
});
25+
26+
throws(() => new URLPattern({}, { ignoreCase: '' }), {
27+
code: 'ERR_INVALID_ARG_TYPE',
28+
});
29+
30+
const pattern = new URLPattern();
31+
32+
throws(() => pattern.exec(1), {
33+
code: 'ERR_INVALID_ARG_TYPE',
34+
});
35+
36+
throws(() => pattern.exec('', 1), {
37+
code: 'ERR_INVALID_ARG_TYPE',
38+
});
39+
40+
throws(() => pattern.test(1), {
41+
code: 'ERR_INVALID_ARG_TYPE',
42+
});
43+
44+
throws(() => pattern.test('', 1), {
45+
code: 'ERR_INVALID_ARG_TYPE',
46+
});

0 commit comments

Comments
 (0)