Skip to content

Commit 270c432

Browse files
committed
fix: normalize preferGET specified values to origin
- Normalize `preferGET` values to its origin as initial implementation (which expects user specified values are always sematntically correct "origin") is error-prone - Change link to "origin" spec atReadme from developer.mozilla.org to url.spec.whatwg.org
1 parent ffd5998 commit 270c432

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

ReadMe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Example:
110110

111111
### preferGET
112112

113-
An array of [origins](https://developer.mozilla.org/en-US/docs/Web/API/URL/origin) to lets the rule connect to the origin's URL by `GET` instead of default `HEAD` request.
113+
An array of [origins](https://url.spec.whatwg.org/#origin) to lets the rule connect to the origin's URL by `GET` instead of default `HEAD` request.
114114

115115
Although the rule will fall back to `GET` method when `HEAD` request is failed (status code is not between 200 and 300), in order to shorten time to run your test, you can use this option when you are sure that target origin always returns 5xx for `HEAD` request.
116116

src/no-dead-link.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ function reporter(context, options = {}) {
163163
}
164164

165165
const method =
166-
opts.preferGET.filter((origin) => getURLOrigin(uri) === origin).length > 0
166+
opts.preferGET.filter(
167+
(origin) => getURLOrigin(uri) === getURLOrigin(origin),
168+
).length > 0
167169
? 'GET'
168170
: 'HEAD';
169171

test/no-dead-link.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ tester.run('no-dead-link', rule, {
6565
preferGET: ['https://www.npmjs.com'],
6666
},
6767
},
68+
{
69+
text:
70+
'should success with GET method whether the option is specific URL: [npm results for textlint](https://www.npmjs.com/search?q=textlint)',
71+
options: {
72+
preferGET: ['https://www.npmjs.com/search?q=textlint-rule'],
73+
},
74+
},
6875
],
6976
invalid: [
7077
{

0 commit comments

Comments
 (0)