From c6ca15cab9b0457301a110edb3fe7a2bd46c17e2 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Fri, 19 Jul 2024 10:02:47 +0100 Subject: [PATCH] refactor(index): regex updates (#136) * refactor(index): use `i` case-insensitive flag over character ranges * refactor(index): use word character inside regex character class --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index b48a33d..dec9189 100644 --- a/index.js +++ b/index.js @@ -22,7 +22,7 @@ const MissingOrBadAuthorizationHeader = createError( * The scheme name is "Basic". * @see https://datatracker.ietf.org/doc/html/rfc7617#section-2 */ -const authScheme = '(?:[Bb][Aa][Ss][Ii][Cc])' +const authScheme = '(?:basic)' /** * The BWS rule is used where the grammar allows optional whitespace * only for historical reasons. A sender MUST NOT generate BWS in @@ -40,14 +40,14 @@ const BWS = '[ \t]' * ([RFC4648]). * @see https://datatracker.ietf.org/doc/html/rfc7235#section-2.1 */ -const token68 = '([A-Za-z0-9._~+/-]+=*)' +const token68 = '([\\w.~+/-]+=*)' /** * @see https://datatracker.ietf.org/doc/html/rfc7235#appendix-C */ -const credentialsStrictRE = new RegExp(`^${authScheme} ${token68}$`) +const credentialsStrictRE = new RegExp(`^${authScheme} ${token68}$`, 'i') -const credentialsLaxRE = new RegExp(`^${BWS}*${authScheme}${BWS}+${token68}${BWS}*$`) +const credentialsLaxRE = new RegExp(`^${BWS}*${authScheme}${BWS}+${token68}${BWS}*$`, 'i') /** * @see https://datatracker.ietf.org/doc/html/rfc5234#appendix-B.1