Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const SPEC_ALGORITHMS = ['sha256', 'sha384', 'sha512']

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve remove constricting change

const STRICT_SRI_REGEX = /^([^-]+)-([A-Za-z0-9+/=]{44,88})(\?[\x21-\x7E]*)?$/
const VCHAR_REGEX = /^[\x21-\x7E]+$/

const SsriOpts = figgyPudding({
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve remove const SsriOpts = figgyPudding({

Expand Down
28 changes: 28 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,34 @@ test('parses single-entry integrity string', t => {
t.done()
})

test('parses options from integrity string', t => {
const sha = hash(TEST_DATA, 'sha512')
const integrity = `sha512-${sha}?one?two?three`
t.deepEqual(ssri.parse(integrity), {
sha512: [{
source: integrity,
digest: sha,
algorithm: 'sha512',
options: ['one', 'two', 'three']
}]
}, 'single entry parsed into full Integrity instance')
t.done()
})

test('parses options from integrity string in strict mode', t => {
const sha = hash(TEST_DATA, 'sha512')
const integrity = `sha512-${sha}?one?two?three`
t.deepEqual(ssri.parse(integrity, { strict: true }), {
sha512: [{
source: integrity,
digest: sha,
algorithm: 'sha512',
options: ['one', 'two', 'three']
}]
}, 'single entry parsed into full Integrity instance')
t.done()
})

test('can parse single-entry string directly into Hash', t => {
const sha = hash(TEST_DATA, 'sha512')
const integrity = `sha512-${sha}`
Expand Down