| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 086b893 commit 589a8d4
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -409,8 +409,12 @@ void BindingData::Update(const FunctionCallbackInfo<Value>& args) { | |||
| 409 | 409 | Utf8Value new_value(isolate, args[2].As<String>()); | |
| 410 | 410 | ||
| 411 | 411 | std::string_view new_value_view = new_value.ToStringView(); | |
| 412 | + // A serialized URL is not always reparsable: the IDNA encoder can emit a | ||
| 413 | + // host label that the decoder rejects. Fail the update instead of crashing. | ||
| 412 | 414 | auto out = ada::parse<ada::url_aggregator>(input.ToStringView()); | |
| 413 | - CHECK(out); | ||
| 415 | + if (!out) { | ||
| 416 | + return args.GetReturnValue().Set(false); | ||
| 417 | + } | ||
| 414 | 418 | ||
| 415 | 419 | bool result{true}; | |
| 416 | 420 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,6 +39,32 @@ const additionalTestCases = | |||
| 39 | 39 | } | |
| 40 | 40 | } | |
| 41 | 41 | ||
| 42 | + // The parser can produce a serialization it rejects when parsing it back: a | ||
| 43 | + // Unicode host encodes to an `xn--xn--` label that the punycode decoder turns | ||
| 44 | + // down. Setters reparse `href`, so the failure must not take the process down. | ||
| 45 | + // Implementations backed by ICU accept that label, and ada does too as of | ||
| 46 | + // https://github.com/ada-url/idna/pull/72, so this URL round-trips once that | ||
| 47 | + // lands here and the setters below apply as usual. | ||
| 48 | + test(function() { | ||
| 49 | + const url = new URL('http:\u{1F600}xn-'); | ||
| 50 | + const setters = { | ||
| 51 | + hostname: 'example.com', | ||
| 52 | + host: 'example.com:8080', | ||
| 53 | + protocol: 'https:', | ||
| 54 | + pathname: '/path', | ||
| 55 | + search: '?search', | ||
| 56 | + hash: '#hash', | ||
| 57 | + port: '8080', | ||
| 58 | + username: 'username', | ||
| 59 | + password: 'password', | ||
| 60 | + }; | ||
| 61 | + | ||
| 62 | + for (const [property, value] of Object.entries(setters)) { | ||
| 63 | + url[property] = value; | ||
| 64 | + assert_equals(typeof url.href, 'string', `Setting ${property} does not crash`); | ||
| 65 | + } | ||
| 66 | + }, 'URL: setting properties with an unparsable serialized URL'); | ||
| 67 | + | ||
| 42 | 68 | { | |
| 43 | 69 | const url = new URL('http://example.com/'); | |
| 44 | 70 | const obj = { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments