Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust SAFE_URL_PATTERN regex for use with test method of regexes. #33136

Merged
merged 3 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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 js/src/util/sanitizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ARIA_ATTRIBUTE_PATTERN = /^aria-[\w-]*$/i
*
* Shoutout to Angular 7 https://github.com/angular/angular/blob/7.2.4/packages/core/src/sanitization/url_sanitizer.ts
*/
const SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file):|[^#&/:?]*(?:[#/?]|$))/gi
const SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file):|[^#&/:?]*(?:[#/?]|$))/i

/**
* A pattern that matches safe data URLs. Only matches image, video and audio types.
Expand Down
10 changes: 10 additions & 0 deletions js/tests/unit/util/sanitizer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,15 @@ describe('Sanitizer', () => {
expect(result).toEqual(template)
expect(DOMParser.prototype.parseFromString).not.toHaveBeenCalled()
})

it('should allow multiple sanitation passes of the same template', () => {
const template = '<img src="test.jpg">'

const firstResult = sanitizeHtml(template, DefaultAllowlist, null)
const secondResult = sanitizeHtml(template, DefaultAllowlist, null)

expect(firstResult).toContain('src')
expect(secondResult).toContain('src')
})
})
})