aboutsummaryrefslogtreecommitdiff
path: root/lib/internal/policy/sri.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/internal/policy/sri.js')
-rw-r--r--lib/internal/policy/sri.js22
1 files changed, 10 insertions, 12 deletions
diff --git a/lib/internal/policy/sri.js b/lib/internal/policy/sri.js
index fff4e066b1..1cdec8d739 100644
--- a/lib/internal/policy/sri.js
+++ b/lib/internal/policy/sri.js
@@ -18,29 +18,27 @@ const { freeze } = Object;
Object.seal(kSRIPattern);
const kAllWSP = new RegExp(`^${kWSP}*$`);
Object.seal(kAllWSP);
+
const RegExpExec = Function.call.bind(RegExp.prototype.exec);
const RegExpTest = Function.call.bind(RegExp.prototype.test);
const StringSlice = Function.call.bind(String.prototype.slice);
-const {
- Buffer: {
- from: BufferFrom
- }
-} = require('buffer');
+
+const BufferFrom = require('buffer').Buffer.from;
const { defineProperty } = Object;
+
const parse = (str) => {
kSRIPattern.lastIndex = 0;
let prevIndex = 0;
- let match = RegExpExec(kSRIPattern, str);
+ let match;
const entries = [];
- while (match) {
+ while (match = RegExpExec(kSRIPattern, str)) {
if (match.index !== prevIndex) {
throw new ERR_SRI_PARSE(str, prevIndex);
}
- if (entries.length > 0) {
- if (match[1] === '') {
- throw new ERR_SRI_PARSE(str, prevIndex);
- }
+ if (entries.length > 0 && match[1] === '') {
+ throw new ERR_SRI_PARSE(str, prevIndex);
}
+
// Avoid setters being fired
defineProperty(entries, entries.length, {
enumerable: true,
@@ -53,8 +51,8 @@ const parse = (str) => {
})
});
prevIndex = prevIndex + match[0].length;
- match = RegExpExec(kSRIPattern, str);
}
+
if (prevIndex !== str.length) {
if (!RegExpTest(kAllWSP, StringSlice(str, prevIndex))) {
throw new ERR_SRI_PARSE(str, prevIndex);