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. #33153

Merged
merged 2 commits into from
Mar 2, 2021
Merged
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 js/src/tools/sanitizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const DefaultWhitelist = {
*
* 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
20 changes: 20 additions & 0 deletions js/tests/unit/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -1333,4 +1333,24 @@ $(function () {
assert.strictEqual(tooltip.hasClass('a b'), true)
assert.strictEqual(tooltip.hasClass('tooltip fade bs-tooltip-top show'), true)
})

QUnit.test('HTML content can be passed through sanitation multiple times', function (assert) {
assert.expect(2)

// Add the same tooltip twice, so the template will be sanitized twice as well.
for (var i = 0; i <= 1; i++) {
$('<a href="#" rel="tooltip" data-trigger="click" title="<img src=\'test.jpg\'>" />')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
html: true
})
.bootstrapTooltip('show')
}

var tooltip1Image = $('.tooltip:first img')
var tooltip2Image = $('.tooltip:last img')

assert.strictEqual(tooltip1Image.attr('src'), 'test.jpg')
assert.strictEqual(tooltip2Image.attr('src'), 'test.jpg')
})
})