Skip to content

Commit 0f7a37b

Browse files
committed
Pass through non-strings in escapeMarkup
It is assumed that DOM elements or related objects will have been escaped before they are passed back from templating functions. As strings are typically blinding concatenated, like in our defaults, it makes sense to escape the markup within them. This is related to select2#3005.
1 parent 631ae06 commit 0f7a37b

8 files changed

Lines changed: 36 additions & 2 deletions

File tree

dist/js/select2.amd.full.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ define(['jquery'], function ($) {define('select2/utils',[
231231
'/': '/'
232232
};
233233

234+
// Do not try to escape the markup if it's not a string
235+
if (typeof markup !== 'string') {
236+
return markup;
237+
}
238+
234239
return String(markup).replace(/[&<>"'\/\\]/g, function (match) {
235240
return replaceMap[match];
236241
});

dist/js/select2.amd.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ define(['jquery'], function ($) {define('select2/utils',[
231231
'/': '&#47;'
232232
};
233233

234+
// Do not try to escape the markup if it's not a string
235+
if (typeof markup !== 'string') {
236+
return markup;
237+
}
238+
234239
return String(markup).replace(/[&<>"'\/\\]/g, function (match) {
235240
return replaceMap[match];
236241
});

dist/js/select2.full.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,11 @@ define('select2/utils',[
669669
'/': '&#47;'
670670
};
671671

672+
// Do not try to escape the markup if it's not a string
673+
if (typeof markup !== 'string') {
674+
return markup;
675+
}
676+
672677
return String(markup).replace(/[&<>"'\/\\]/g, function (match) {
673678
return replaceMap[match];
674679
});

dist/js/select2.full.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/select2.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,11 @@ define('select2/utils',[
669669
'/': '&#47;'
670670
};
671671

672+
// Do not try to escape the markup if it's not a string
673+
if (typeof markup !== 'string') {
674+
return markup;
675+
}
676+
672677
return String(markup).replace(/[&<>"'\/\\]/g, function (match) {
673678
return replaceMap[match];
674679
});

dist/js/select2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/select2/utils.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ define([
231231
'/': '&#47;'
232232
};
233233

234+
// Do not try to escape the markup if it's not a string
235+
if (typeof markup !== 'string') {
236+
return markup;
237+
}
238+
234239
return String(markup).replace(/[&<>"'\/\\]/g, function (match) {
235240
return replaceMap[match];
236241
});

tests/utils/escapeMarkup-tests.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,12 @@ test('quotes are killed as well', function (assert) {
2525
assert.equal(escaped.indexOf('\''), -1);
2626
assert.equal(escaped.indexOf('"'), -1);
2727
});
28+
29+
test('DocumentFragment options pass through', function (assert) {
30+
var frag = document.createDocumentFragment();
31+
frag.innerHTML = '<strong>test</strong>';
32+
33+
var escaped = Utils.escapeMarkup(frag);
34+
35+
assert.equal(frag, escaped);
36+
});

0 commit comments

Comments
 (0)