summaryrefslogtreecommitdiff
path: root/ext/web
diff options
context:
space:
mode:
Diffstat (limited to 'ext/web')
-rw-r--r--ext/web/00_infra.js20
-rw-r--r--ext/web/09_file.js5
2 files changed, 15 insertions, 10 deletions
diff --git a/ext/web/00_infra.js b/ext/web/00_infra.js
index 0a8491563..cff0f66d8 100644
--- a/ext/web/00_infra.js
+++ b/ext/web/00_infra.js
@@ -15,8 +15,8 @@ const {
Error,
JSONStringify,
NumberPrototypeToString,
- RegExp,
SafeArrayIterator,
+ SafeRegExp,
String,
StringPrototypeCharAt,
StringPrototypeCharCodeAt,
@@ -67,7 +67,7 @@ const HTTP_TOKEN_CODE_POINT = [
"\u007E",
...new SafeArrayIterator(ASCII_ALPHANUMERIC),
];
-const HTTP_TOKEN_CODE_POINT_RE = new RegExp(
+const HTTP_TOKEN_CODE_POINT_RE = new SafeRegExp(
`^[${regexMatcher(HTTP_TOKEN_CODE_POINT)}]+$`,
);
const HTTP_QUOTED_STRING_TOKEN_POINT = [
@@ -75,27 +75,27 @@ const HTTP_QUOTED_STRING_TOKEN_POINT = [
"\u0020-\u007E",
"\u0080-\u00FF",
];
-const HTTP_QUOTED_STRING_TOKEN_POINT_RE = new RegExp(
+const HTTP_QUOTED_STRING_TOKEN_POINT_RE = new SafeRegExp(
`^[${regexMatcher(HTTP_QUOTED_STRING_TOKEN_POINT)}]+$`,
);
const HTTP_TAB_OR_SPACE_MATCHER = regexMatcher(HTTP_TAB_OR_SPACE);
-const HTTP_TAB_OR_SPACE_PREFIX_RE = new RegExp(
+const HTTP_TAB_OR_SPACE_PREFIX_RE = new SafeRegExp(
`^[${HTTP_TAB_OR_SPACE_MATCHER}]+`,
"g",
);
-const HTTP_TAB_OR_SPACE_SUFFIX_RE = new RegExp(
+const HTTP_TAB_OR_SPACE_SUFFIX_RE = new SafeRegExp(
`[${HTTP_TAB_OR_SPACE_MATCHER}]+$`,
"g",
);
const HTTP_WHITESPACE_MATCHER = regexMatcher(HTTP_WHITESPACE);
-const HTTP_BETWEEN_WHITESPACE = new RegExp(
+const HTTP_BETWEEN_WHITESPACE = new SafeRegExp(
`^[${HTTP_WHITESPACE_MATCHER}]*(.*?)[${HTTP_WHITESPACE_MATCHER}]*$`,
);
-const HTTP_WHITESPACE_PREFIX_RE = new RegExp(
+const HTTP_WHITESPACE_PREFIX_RE = new SafeRegExp(
`^[${HTTP_WHITESPACE_MATCHER}]+`,
"g",
);
-const HTTP_WHITESPACE_SUFFIX_RE = new RegExp(
+const HTTP_WHITESPACE_SUFFIX_RE = new SafeRegExp(
`[${HTTP_WHITESPACE_MATCHER}]+$`,
"g",
);
@@ -150,6 +150,8 @@ function collectSequenceOfCodepoints(input, position, condition) {
return { result: StringPrototypeSlice(input, start, position), position };
}
+const LOWERCASE_PATTERN = new SafeRegExp(/[a-z]/g);
+
/**
* @param {string} s
* @returns {string}
@@ -157,7 +159,7 @@ function collectSequenceOfCodepoints(input, position, condition) {
function byteUpperCase(s) {
return StringPrototypeReplace(
String(s),
- /[a-z]/g,
+ LOWERCASE_PATTERN,
function byteUpperCaseReplace(c) {
return StringPrototypeToUpperCase(c);
},
diff --git a/ext/web/09_file.js b/ext/web/09_file.js
index b44537dd4..c2fe7782c 100644
--- a/ext/web/09_file.js
+++ b/ext/web/09_file.js
@@ -29,6 +29,7 @@ const {
RegExpPrototypeTest,
// TODO(lucacasonato): add SharedArrayBuffer to primordials
// SharedArrayBufferPrototype
+ SafeRegExp,
StringPrototypeCharAt,
StringPrototypeToLowerCase,
StringPrototypeSlice,
@@ -143,13 +144,15 @@ function processBlobParts(parts, endings) {
return { parts: processedParts, size };
}
+const NORMALIZE_PATTERN = new SafeRegExp(/^[\x20-\x7E]*$/);
+
/**
* @param {string} str
* @returns {string}
*/
function normalizeType(str) {
let normalizedType = str;
- if (!RegExpPrototypeTest(/^[\x20-\x7E]*$/, str)) {
+ if (!RegExpPrototypeTest(NORMALIZE_PATTERN, str)) {
normalizedType = "";
}
return StringPrototypeToLowerCase(normalizedType);