1
0
mirror of synced 2025-02-03 21:59:24 +03:00

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 https://github.com/select2/select2/issues/3005.
This commit is contained in:
Kevin Brown 2015-02-06 19:45:10 -05:00
parent 631ae06c8d
commit 0f7a37b2d6
8 changed files with 36 additions and 2 deletions

View File

@ -231,6 +231,11 @@ define(['jquery'], function ($) {define('select2/utils',[
'/': '/'
};
// Do not try to escape the markup if it's not a string
if (typeof markup !== 'string') {
return markup;
}
return String(markup).replace(/[&<>"'\/\\]/g, function (match) {
return replaceMap[match];
});

View File

@ -231,6 +231,11 @@ define(['jquery'], function ($) {define('select2/utils',[
'/': '&#47;'
};
// Do not try to escape the markup if it's not a string
if (typeof markup !== 'string') {
return markup;
}
return String(markup).replace(/[&<>"'\/\\]/g, function (match) {
return replaceMap[match];
});

View File

@ -669,6 +669,11 @@ define('select2/utils',[
'/': '&#47;'
};
// Do not try to escape the markup if it's not a string
if (typeof markup !== 'string') {
return markup;
}
return String(markup).replace(/[&<>"'\/\\]/g, function (match) {
return replaceMap[match];
});

File diff suppressed because one or more lines are too long

5
dist/js/select2.js vendored
View File

@ -669,6 +669,11 @@ define('select2/utils',[
'/': '&#47;'
};
// Do not try to escape the markup if it's not a string
if (typeof markup !== 'string') {
return markup;
}
return String(markup).replace(/[&<>"'\/\\]/g, function (match) {
return replaceMap[match];
});

File diff suppressed because one or more lines are too long

View File

@ -231,6 +231,11 @@ define([
'/': '&#47;'
};
// Do not try to escape the markup if it's not a string
if (typeof markup !== 'string') {
return markup;
}
return String(markup).replace(/[&<>"'\/\\]/g, function (match) {
return replaceMap[match];
});

View File

@ -25,3 +25,12 @@ test('quotes are killed as well', function (assert) {
assert.equal(escaped.indexOf('\''), -1);
assert.equal(escaped.indexOf('"'), -1);
});
test('DocumentFragment options pass through', function (assert) {
var frag = document.createDocumentFragment();
frag.innerHTML = '<strong>test</strong>';
var escaped = Utils.escapeMarkup(frag);
assert.equal(frag, escaped);
});