Skip to content

Commit b30dfdb

Browse files
committed
fix: backport regex change from 8.0.1
PR-URL: #19 Credit: @nlf Close: #19 Reviewed-by: @wraithgar
1 parent a4337cd commit b30dfdb

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const SPEC_ALGORITHMS = ['sha256', 'sha384', 'sha512']
88

99
const BASE64_REGEX = /^[a-z0-9+/]+(?:=?=?)$/i
1010
const SRI_REGEX = /^([^-]+)-([^?]+)([?\S*]*)$/
11-
const STRICT_SRI_REGEX = /^([^-]+)-([A-Za-z0-9+/=]{44,88})(\?[\x21-\x7E]*)*$/
11+
const STRICT_SRI_REGEX = /^([^-]+)-([A-Za-z0-9+/=]{44,88})(\?[\x21-\x7E]*)?$/
1212
const VCHAR_REGEX = /^[\x21-\x7E]+$/
1313

1414
const SsriOpts = figgyPudding({

test/parse.js

+28
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,34 @@ test('parses single-entry integrity string', t => {
2626
t.done()
2727
})
2828

29+
test('parses options from integrity string', t => {
30+
const sha = hash(TEST_DATA, 'sha512')
31+
const integrity = `sha512-${sha}?one?two?three`
32+
t.deepEqual(ssri.parse(integrity), {
33+
sha512: [{
34+
source: integrity,
35+
digest: sha,
36+
algorithm: 'sha512',
37+
options: ['one', 'two', 'three']
38+
}]
39+
}, 'single entry parsed into full Integrity instance')
40+
t.done()
41+
})
42+
43+
test('parses options from integrity string in strict mode', t => {
44+
const sha = hash(TEST_DATA, 'sha512')
45+
const integrity = `sha512-${sha}?one?two?three`
46+
t.deepEqual(ssri.parse(integrity, { strict: true }), {
47+
sha512: [{
48+
source: integrity,
49+
digest: sha,
50+
algorithm: 'sha512',
51+
options: ['one', 'two', 'three']
52+
}]
53+
}, 'single entry parsed into full Integrity instance')
54+
t.done()
55+
})
56+
2957
test('can parse single-entry string directly into Hash', t => {
3058
const sha = hash(TEST_DATA, 'sha512')
3159
const integrity = `sha512-${sha}`

0 commit comments

Comments
 (0)