From 498aed2add0d8adccedae3c6be4572f2ba10384d Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sat, 16 Sep 2023 21:19:14 +0100 Subject: [PATCH 1/3] refactor(index): use word character inside regex character class --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 0a90f6f..40729c9 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,7 @@ NullObject.prototype = Object.create(null) * obs-text = %x80-FF * quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text ) */ -const paramRE = /; *([!#$%&'*+.^_`|~0-9A-Za-z-]+)=("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^_`|~0-9A-Za-z-]+) */g // eslint-disable-line no-control-regex +const paramRE = /; *([!#$%&'*+.^\w`|~-]+)=("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^\w`|~-]+) */g // eslint-disable-line no-control-regex /** * RegExp to match quoted-pair in RFC 7230 sec 3.2.6 @@ -34,7 +34,7 @@ const quotedPairRE = /\\([\u000b\u0020-\u00ff])/g // eslint-disable-line no-cont * type = token * subtype = token */ -const mediaTypeRE = /^[!#$%&'*+.^_|~0-9A-Za-z-]+\/[!#$%&'*+.^_|~0-9A-Za-z-]+$/ +const mediaTypeRE = /^[!#$%&'*+.^\w|~-]+\/[!#$%&'*+.^\w|~-]+$/ // default ContentType to prevent repeated object creation const defaultContentType = { type: '', parameters: new NullObject() } From cdf6d9232ad84e9d78e68d09af302fd4ac836d4e Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sat, 16 Sep 2023 21:54:33 +0100 Subject: [PATCH 2/3] refactor(index): use `\v` vertical whitespace char over unicode --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 40729c9..1ece811 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,7 @@ NullObject.prototype = Object.create(null) * obs-text = %x80-FF * quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text ) */ -const paramRE = /; *([!#$%&'*+.^\w`|~-]+)=("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^\w`|~-]+) */g // eslint-disable-line no-control-regex +const paramRE = /; *([!#$%&'*+.^\w`|~-]+)=("(?:[\v\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\v\u0020-\u00ff])*"|[!#$%&'*+.^\w`|~-]+) */g /** * RegExp to match quoted-pair in RFC 7230 sec 3.2.6 @@ -25,7 +25,7 @@ const paramRE = /; *([!#$%&'*+.^\w`|~-]+)=("(?:[\u000b\u0020\u0021\u0023-\u005b\ * quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text ) * obs-text = %x80-FF */ -const quotedPairRE = /\\([\u000b\u0020-\u00ff])/g // eslint-disable-line no-control-regex +const quotedPairRE = /\\([\v\u0020-\u00ff])/g /** * RegExp to match type in RFC 7231 sec 3.1.1.1 From 563acc31ef192cef04448ae3e6e4f54a6afca505 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 17 Sep 2023 08:11:59 +0100 Subject: [PATCH 3/3] refactor(index): add `u` unicode flag to regex --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 1ece811..438ef1e 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,7 @@ NullObject.prototype = Object.create(null) * obs-text = %x80-FF * quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text ) */ -const paramRE = /; *([!#$%&'*+.^\w`|~-]+)=("(?:[\v\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\v\u0020-\u00ff])*"|[!#$%&'*+.^\w`|~-]+) */g +const paramRE = /; *([!#$%&'*+.^\w`|~-]+)=("(?:[\v\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\v\u0020-\u00ff])*"|[!#$%&'*+.^\w`|~-]+) */gu /** * RegExp to match quoted-pair in RFC 7230 sec 3.2.6 @@ -25,7 +25,7 @@ const paramRE = /; *([!#$%&'*+.^\w`|~-]+)=("(?:[\v\u0020\u0021\u0023-\u005b\u005 * quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text ) * obs-text = %x80-FF */ -const quotedPairRE = /\\([\v\u0020-\u00ff])/g +const quotedPairRE = /\\([\v\u0020-\u00ff])/gu /** * RegExp to match type in RFC 7231 sec 3.1.1.1 @@ -34,7 +34,7 @@ const quotedPairRE = /\\([\v\u0020-\u00ff])/g * type = token * subtype = token */ -const mediaTypeRE = /^[!#$%&'*+.^\w|~-]+\/[!#$%&'*+.^\w|~-]+$/ +const mediaTypeRE = /^[!#$%&'*+.^\w|~-]+\/[!#$%&'*+.^\w|~-]+$/u // default ContentType to prevent repeated object creation const defaultContentType = { type: '', parameters: new NullObject() }