Skip to content

Commit 257ae3a

Browse files
Trim the result of URLs in "href". (#302)
* Trim the result of URLs in "href". fixes #301 * Fix CI
1 parent 3067bdd commit 257ae3a

File tree

7 files changed

+14
-8
lines changed

7 files changed

+14
-8
lines changed

.github/workflows/node.js.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ jobs:
1515
node-version: [20]
1616

1717
steps:
18-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v4
1919
- name: Use Node.js ${{ matrix.node-version }}
20-
uses: actions/setup-node@v2
20+
uses: actions/setup-node@v4
2121
with:
2222
node-version: ${{ matrix.node-version }}
2323
cache: 'npm'

cjs/html/anchor-element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class HTMLAnchorElement extends HTMLElement {
1515
}
1616

1717
/* c8 ignore start */ // copy paste from img.src, already covered
18-
get href() { return encodeURI(decodeURI(stringAttribute.get(this, 'href'))); }
18+
get href() { return encodeURI(decodeURI(stringAttribute.get(this, 'href'))).trim(); }
1919
set href(value) { stringAttribute.set(this, 'href', decodeURI(value)); }
2020

2121
get download() { return encodeURI(decodeURI(stringAttribute.get(this, 'download'))); }

cjs/html/link-element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class HTMLLinkElement extends HTMLElement {
1818
get disabled() { return booleanAttribute.get(this, 'disabled'); }
1919
set disabled(value) { booleanAttribute.set(this, 'disabled', value); }
2020

21-
get href() { return stringAttribute.get(this, 'href'); }
21+
get href() { return stringAttribute.get(this, 'href').trim(); }
2222
set href(value) { stringAttribute.set(this, 'href', value); }
2323

2424
get hreflang() { return stringAttribute.get(this, 'hreflang'); }

esm/html/anchor-element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class HTMLAnchorElement extends HTMLElement {
1414
}
1515

1616
/* c8 ignore start */ // copy paste from img.src, already covered
17-
get href() { return encodeURI(decodeURI(stringAttribute.get(this, 'href'))); }
17+
get href() { return encodeURI(decodeURI(stringAttribute.get(this, 'href'))).trim(); }
1818
set href(value) { stringAttribute.set(this, 'href', decodeURI(value)); }
1919

2020
get download() { return encodeURI(decodeURI(stringAttribute.get(this, 'download'))); }

esm/html/link-element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class HTMLLinkElement extends HTMLElement {
1717
get disabled() { return booleanAttribute.get(this, 'disabled'); }
1818
set disabled(value) { booleanAttribute.set(this, 'disabled', value); }
1919

20-
get href() { return stringAttribute.get(this, 'href'); }
20+
get href() { return stringAttribute.get(this, 'href').trim(); }
2121
set href(value) { stringAttribute.set(this, 'href', value); }
2222

2323
get hreflang() { return stringAttribute.get(this, 'hreflang'); }

test/html/anchor-element.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ a.setAttribute('href', 'https://google.com/?q=asd&lol=<2>"');
1313
assert(a.href, 'https://google.com/?q=asd&lol=%3C2%3E%22');
1414
a.setAttribute('href', 'https://google.com/path%20to%20some%20file.pdf');
1515
assert(a.href, 'https://google.com/path%20to%20some%20file.pdf');
16+
17+
// "href" should trim links, but getAttribute should preserve the original value
18+
const untrimmedLink = ' https://example.com/\n ';
19+
const hrefExample = parseHTML( `<!DOCTYPE html><html><head><title>Test</title><link rel='canonical' href="${untrimmedLink}"></head><body></body></html>`, 'text/html').document.querySelector('link');
20+
assert(hrefExample.href, 'https://example.com/');
21+
assert(hrefExample.getAttribute('href'), untrimmedLink);

worker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11575,7 +11575,7 @@ class HTMLLinkElement extends HTMLElement {
1157511575
get disabled() { return booleanAttribute.get(this, 'disabled'); }
1157611576
set disabled(value) { booleanAttribute.set(this, 'disabled', value); }
1157711577

11578-
get href() { return stringAttribute.get(this, 'href'); }
11578+
get href() { return stringAttribute.get(this, 'href').trim(); }
1157911579
set href(value) { stringAttribute.set(this, 'href', value); }
1158011580

1158111581
get hreflang() { return stringAttribute.get(this, 'hreflang'); }
@@ -11792,7 +11792,7 @@ class HTMLAnchorElement extends HTMLElement {
1179211792
}
1179311793

1179411794
/* c8 ignore start */ // copy paste from img.src, already covered
11795-
get href() { return encodeURI(decodeURI(stringAttribute.get(this, 'href'))); }
11795+
get href() { return encodeURI(decodeURI(stringAttribute.get(this, 'href'))).trim(); }
1179611796
set href(value) { stringAttribute.set(this, 'href', decodeURI(value)); }
1179711797

1179811798
get download() { return encodeURI(decodeURI(stringAttribute.get(this, 'download'))); }

0 commit comments

Comments
 (0)