Skip to content

Commit

Permalink
#4163 #4164 More general fix that properly escapes string values for …
Browse files Browse the repository at this point in the history
…selectors
  • Loading branch information
jlukic committed Feb 21, 2017
1 parent 9be5cf2 commit 6f19675
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/definitions/behaviors/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,6 @@ $.fn.form = function(parameters) {
}
});
return allValid;
},
validHTMLID(value) {
if(typeof value !== 'string') {
return false;
}
return value.search(regExp.htmlID) !== -1;
}
},

Expand Down Expand Up @@ -485,7 +479,8 @@ $.fn.form = function(parameters) {
},
field: function(identifier) {
module.verbose('Finding field with identifier', identifier);
if(module.is.validHTMLID(identifier) && $field.filter('#' + identifier).length > 0 ) {
identifier = module.escape.string(identifier);
if($field.filter('#' + identifier).length > 0 ) {
return $field.filter('#' + identifier);
}
else if( $field.filter('[name="' + identifier +'"]').length > 0 ) {
Expand Down Expand Up @@ -600,10 +595,11 @@ $.fn.form = function(parameters) {

field: function(identifier) {
module.verbose('Checking for existence of a field with identifier', identifier);
identifier = module.escape.regExp(identifier);
if(typeof identifier !== 'string') {
module.error(error.identifier, identifier);
}
if(module.is.validHTMLID(identifier) && $field.filter('#' + identifier).length > 0 ) {
if($field.filter('#' + identifier).length > 0 ) {
return true;
}
else if( $field.filter('[name="' + identifier +'"]').length > 0 ) {
Expand All @@ -617,6 +613,13 @@ $.fn.form = function(parameters) {

},

escape: {
string: function(text) {
text = String(text);
return text.replace(regExp.escape, '\\$&');
}
},

add: {
prompt: function(identifier, errors) {
var
Expand Down

0 comments on commit 6f19675

Please sign in to comment.