mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-08 14:46:34 +02:00
Adjust regex SAFE_URL_PATTERN
for use with test method of regexes. (#33136)
The test method on regexes behaves different than the match method on strings in the presence of the global modifier. Add a unit test for sanitizing the same template twice. Co-authored-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
@@ -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
|
* 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.
|
* A pattern that matches safe data URLs. Only matches image, video and audio types.
|
||||||
|
@@ -66,5 +66,15 @@ describe('Sanitizer', () => {
|
|||||||
expect(result).toEqual(template)
|
expect(result).toEqual(template)
|
||||||
expect(DOMParser.prototype.parseFromString).not.toHaveBeenCalled()
|
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')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user