Skip to content

Commit

Permalink
fix(dropdown): values are incorrect if they contain some special chars
Browse files Browse the repository at this point in the history
Dropdown values which are supposed to be encoded into htmlentities like < were wrongly encoded whenever the values changed. Especially when working with mulitple selection dropdowns.
Reason for this was the overseen fact that an ampersand & was also encoded into &. As htmlentities are in general encoded by starting with an ampersand aswell this was totally messing up the value string.

As the escape routine was also implemented in other modules, this PR fixes the logic there as well

Closes #1207
  • Loading branch information
lubber-de authored and Sean committed Dec 22, 2019
1 parent a0a537b commit fa50976
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
13 changes: 7 additions & 6 deletions src/definitions/modules/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -2075,7 +2075,7 @@ $.fn.dropdown = function(parameters) {
return;
}
if(isMultiple) {
if($.inArray( String(optionValue), value) !== -1) {
if($.inArray(module.escape.htmlEntities(String(optionValue)), value) !== -1) {
$selectedItem = ($selectedItem)
? $selectedItem.add($choice)
: $choice
Expand All @@ -2094,7 +2094,7 @@ $.fn.dropdown = function(parameters) {
optionValue = optionValue.toLowerCase();
value = value.toLowerCase();
}
if( String(optionValue) == String(value)) {
if(module.escape.htmlEntities(String(optionValue)) === module.escape.htmlEntities(String(value))) {
module.verbose('Found select item by value', optionValue, value);
$selectedItem = $choice;
return true;
Expand Down Expand Up @@ -3067,6 +3067,7 @@ $.fn.dropdown = function(parameters) {
values = module.get.values(),
newValue
;
removedValue = module.escape.htmlEntities(removedValue);
if( module.has.selectInput() ) {
module.verbose('Input is <select> removing selected option', removedValue);
newValue = module.remove.arrayValue(removedValue, values);
Expand Down Expand Up @@ -3656,10 +3657,9 @@ $.fn.dropdown = function(parameters) {
},
htmlEntities: function(string) {
var
badChars = /[&<>"'`]/g,
badChars = /[<>"'`]/g,
shouldEscape = /[&<>"'`]/,
escape = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
Expand All @@ -3671,6 +3671,7 @@ $.fn.dropdown = function(parameters) {
}
;
if(shouldEscape.test(string)) {
string = string.replace(/&(?![a-z0-9#]{1,6};)/, "&amp;");
return string.replace(badChars, escapedChar);
}
return string;
Expand Down Expand Up @@ -4083,10 +4084,9 @@ $.fn.dropdown.settings.templates = {
return string;
}
var
badChars = /[&<>"'`]/g,
badChars = /[<>"'`]/g,
shouldEscape = /[&<>"'`]/,
escape = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
Expand All @@ -4098,6 +4098,7 @@ $.fn.dropdown.settings.templates = {
}
;
if(shouldEscape.test(string)) {
string = string.replace(/&(?![a-z0-9#]{1,6};)/, "&amp;");
return string.replace(badChars, escapedChar);
}
return string;
Expand Down
4 changes: 2 additions & 2 deletions src/definitions/modules/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -1496,10 +1496,9 @@ $.fn.popup.settings = {
templates: {
escape: function(string) {
var
badChars = /[&<>"'`]/g,
badChars = /[<>"'`]/g,
shouldEscape = /[&<>"'`]/,
escape = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
Expand All @@ -1511,6 +1510,7 @@ $.fn.popup.settings = {
}
;
if(shouldEscape.test(string)) {
string = string.replace(/&(?![a-z0-9#]{1,6};)/, "&amp;");
return string.replace(badChars, escapedChar);
}
return string;
Expand Down
4 changes: 2 additions & 2 deletions src/definitions/modules/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -1369,10 +1369,9 @@ $.fn.search.settings = {
return string;
}
var
badChars = /[&<>"'`]/g,
badChars = /[<>"'`]/g,
shouldEscape = /[&<>"'`]/,
escape = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
Expand All @@ -1384,6 +1383,7 @@ $.fn.search.settings = {
}
;
if(shouldEscape.test(string)) {
string = string.replace(/&(?![a-z0-9#]{1,6};)/, "&amp;");
return string.replace(badChars, escapedChar);
}
return string;
Expand Down
4 changes: 2 additions & 2 deletions src/definitions/modules/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,9 @@ $.fn.toast = function(parameters) {
return string;
}
var
badChars = /[&<>"'`]/g,
badChars = /[<>"'`]/g,
shouldEscape = /[&<>"'`]/,
escape = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
Expand All @@ -534,6 +533,7 @@ $.fn.toast = function(parameters) {
}
;
if(shouldEscape.test(string)) {
string = string.replace(/&(?![a-z0-9#]{1,6};)/, "&amp;");
return string.replace(badChars, escapedChar);
}
return string;
Expand Down

0 comments on commit fa50976

Please sign in to comment.