Skip to content

Commit

Permalink
Perform URL encoding (instead of form encoding) of location data.
Browse files Browse the repository at this point in the history
This properly encodes space (%20) and + (%2B) characters.
  • Loading branch information
kbuckler authored and quirkey committed Oct 29, 2010
1 parent 9b8a48e commit da1c89e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/sammy.js
Expand Up @@ -13,6 +13,7 @@
_isFunction = function( obj ) { return Object.prototype.toString.call(obj) === "[object Function]"; },
_isArray = function( obj ) { return Object.prototype.toString.call(obj) === "[object Array]"; },
_decode = decodeURIComponent,
_encode = encodeURIComponent,
_escapeHTML = function(s) {
return s.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
},
Expand Down Expand Up @@ -1190,7 +1191,7 @@
if (!verb || verb == '') { verb = 'get'; }
this.log('_checkFormSubmission', $form, path, verb);
if (verb === 'get') {
this.setLocation(path + '?' + $form.serialize());
this.setLocation(path + '?' + this._serializeFormParams($form));
returned = false;
} else {
params = $.extend({}, this._parseFormParams($form));
Expand All @@ -1199,6 +1200,23 @@
return (typeof returned == 'undefined') ? false : returned;
},

_serializeFormParams: function($form) {
var queryString = "",
fields = $form.serializeArray(),
i;
if (fields.length > 0) {
queryString = this._encodeFormPair(fields[0].name, fields[0].value);
for (i = 1; i < fields.length; i++) {
queryString = queryString + "&" + this._encodeFormPair(fields[i].name, fields[i].value);
}
}
return queryString;
},

_encodeFormPair: function(name, value){
return _encode(name) + "=" + _encode(value);
},

_parseFormParams: function($form) {
var params = {},
form_fields = $form.serializeArray(),
Expand Down

0 comments on commit da1c89e

Please sign in to comment.