From f412834151bbe74dc481fd5cf76654460b47dcc8 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Fri, 14 Oct 2022 18:51:52 +0300 Subject: [PATCH] lib: support more attributes for early hint link PR-URL: https://github.com/nodejs/node/pull/44874 Reviewed-By: Matteo Collina Reviewed-By: James M Snell --- lib/internal/validators.js | 2 +- test/parallel/test-validators.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/internal/validators.js b/lib/internal/validators.js index 8fb3eed9646042..20b7486315cf1f 100644 --- a/lib/internal/validators.js +++ b/lib/internal/validators.js @@ -441,7 +441,7 @@ function validateUnion(value, name, union) { } } -const linkValueRegExp = /^(?:<[^>]*>;)\s*(?:rel=(")?[^;"]*\1;?)\s*(?:(?:as|anchor|title)=(")?[^;"]*\2)?$/; +const linkValueRegExp = /^(?:<[^>]*>;)\s*(?:rel=(")?[^;"]*\1;?)\s*(?:(?:as|anchor|title|crossorigin|disabled|fetchpriority|rel|referrerpolicy)=(")?[^;"]*\2)?$/; /** * @param {any} value diff --git a/test/parallel/test-validators.js b/test/parallel/test-validators.js index 63cf42e306605c..a40139678eee65 100644 --- a/test/parallel/test-validators.js +++ b/test/parallel/test-validators.js @@ -12,6 +12,7 @@ const { validateString, validateInt32, validateUint32, + validateLinkHeaderValue, } = require('internal/validators'); const { MAX_SAFE_INTEGER, MIN_SAFE_INTEGER } = Number; const outOfRangeError = { @@ -154,3 +155,15 @@ const invalidArgValueError = { code: 'ERR_INVALID_ARG_TYPE' })); } + +{ + // validateLinkHeaderValue type validation. + [ + ['; rel=preload; as=style', '; rel=preload; as=style'], + ['; rel=preload; title=hello', '; rel=preload; title=hello'], + ['; rel=preload; crossorigin=hello', '; rel=preload; crossorigin=hello'], + ['; rel=preload; disabled=true', '; rel=preload; disabled=true'], + ['; rel=preload; fetchpriority=high', '; rel=preload; fetchpriority=high'], + ['; rel=preload; referrerpolicy=origin', '; rel=preload; referrerpolicy=origin'], + ].forEach(([value, expected]) => assert.strictEqual(validateLinkHeaderValue(value), expected)); +}