GeezerVison is showing github.com — url: validate href setter receiver first · nodejs/node@c8ee016
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/url.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1022,8 +1022,9 @@ class URL { |
1022 | 1022 | } |
1023 | 1023 |
|
1024 | 1024 | set href(value) { |
| 1025 | + const context = this.#context; |
1025 | 1026 | value = `${value}`; |
1026 | | - const href = bindingUrl.update(this.#context.href, updateActions.kHref, value); |
| 1027 | + const href = bindingUrl.update(context.href, updateActions.kHref, value); |
1027 | 1028 | if (!href) { throw new ERR_INVALID_URL(value); } |
1028 | 1029 | this.#updateContext(href, true); |
1029 | 1030 | } |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-url-custom-href-side-effect.js +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,3 +13,19 @@ assert.throws(() => { |
13 | 13 | }); |
14 | 14 |
|
15 | 15 | assert.deepStrictEqual(url, ref); |
| 16 | + |
| 17 | +const setHref = Object.getOwnPropertyDescriptor(URL.prototype, 'href').set; |
| 18 | +let calls = 0; |
| 19 | + |
| 20 | +assert.throws(() => { |
| 21 | + setHref.call({}, { |
| 22 | + toString() { |
| 23 | + calls++; |
| 24 | + return 'https://example.com/'; |
| 25 | + }, |
| 26 | + }); |
| 27 | +}, { |
| 28 | + name: 'TypeError', |
| 29 | +}); |
| 30 | + |
| 31 | +assert.strictEqual(calls, 0); |