Skip to content

Commit 8199841

Browse files
anonrigRafaelGSS
authored andcommitted
lib: support more attributes for early hint link
PR-URL: #44874 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent c3dd696 commit 8199841

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/internal/validators.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ function validateUnion(value, name, union) {
441441
}
442442
}
443443

444-
const linkValueRegExp = /^(?:<[^>]*>;)\s*(?:rel=(")?[^;"]*\1;?)\s*(?:(?:as|anchor|title)=(")?[^;"]*\2)?$/;
444+
const linkValueRegExp = /^(?:<[^>]*>;)\s*(?:rel=(")?[^;"]*\1;?)\s*(?:(?:as|anchor|title|crossorigin|disabled|fetchpriority|rel|referrerpolicy)=(")?[^;"]*\2)?$/;
445445

446446
/**
447447
* @param {any} value

test/parallel/test-validators.js

+13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const {
1212
validateString,
1313
validateInt32,
1414
validateUint32,
15+
validateLinkHeaderValue,
1516
} = require('internal/validators');
1617
const { MAX_SAFE_INTEGER, MIN_SAFE_INTEGER } = Number;
1718
const outOfRangeError = {
@@ -154,3 +155,15 @@ const invalidArgValueError = {
154155
code: 'ERR_INVALID_ARG_TYPE'
155156
}));
156157
}
158+
159+
{
160+
// validateLinkHeaderValue type validation.
161+
[
162+
['</styles.css>; rel=preload; as=style', '</styles.css>; rel=preload; as=style'],
163+
['</styles.css>; rel=preload; title=hello', '</styles.css>; rel=preload; title=hello'],
164+
['</styles.css>; rel=preload; crossorigin=hello', '</styles.css>; rel=preload; crossorigin=hello'],
165+
['</styles.css>; rel=preload; disabled=true', '</styles.css>; rel=preload; disabled=true'],
166+
['</styles.css>; rel=preload; fetchpriority=high', '</styles.css>; rel=preload; fetchpriority=high'],
167+
['</styles.css>; rel=preload; referrerpolicy=origin', '</styles.css>; rel=preload; referrerpolicy=origin'],
168+
].forEach(([value, expected]) => assert.strictEqual(validateLinkHeaderValue(value), expected));
169+
}

0 commit comments

Comments
 (0)