Skip to content

Commit

Permalink
Coerce set value into string. Fixes #881.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Harding committed Jul 9, 2014
1 parent 3c0e459 commit bd8f259
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/bloodhound/tokenizers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ var tokenizers = (function(root) {
}
};

function toStr(s) { return (_.isUndefined(s) || s === null) ? '' : s + ''; }

function whitespace(str) {
str = toStr(str);
str = _.toStr(str);
return str ? str.split(/\s+/) : [];
}

function nonword(str) {
str = toStr(str);
str = _.toStr(str);
return str ? str.split(/\W+/) : [];
}

Expand All @@ -36,7 +34,7 @@ var tokenizers = (function(root) {
var val, tokens = [];

_.each(args, function(k) {
tokens = tokens.concat(tokenizer(toStr(o[k])));
tokens = tokens.concat(tokenizer(_.toStr(o[k])));
});

return tokens;
Expand Down
4 changes: 4 additions & 0 deletions src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ var _ = (function() {

isUndefined: function(obj) { return typeof obj === 'undefined'; },

toStr: function toStr(s) {
return (_.isUndefined(s) || s === null) ? '' : s + '';
},

bind: $.proxy,

each: function(collection, cb) {
Expand Down
3 changes: 3 additions & 0 deletions src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ var Typeahead = (function() {
},

setVal: function setVal(val) {
// expect val to be a string, so be safe, and coerce
val = _.toStr(val);

if (this.isActivated) {
this.input.setInputValue(val);
}
Expand Down

0 comments on commit bd8f259

Please sign in to comment.