1107153b by Adam Heath

Quote and unquote url parameters, to handle funky chars.

1 parent 0a87101c
......@@ -11,6 +11,20 @@ define(function(require) {
//var module = require('module');
function unquoteUrlValue(value) {
value = value.replace(/\+/g, ' ');
value = value.replace(/%([0-9a-fA-F]{2})/g, function(match, hexValue) {
return String.fromCharCode(parseInt(hexValue, 16));
});
return value;
}
function quoteUrlValue(value) {
// RFC-3986 reserves these chars
return encodeURIComponent(value).replace(/[!'()*]/g, function(c) {
return '%' + c.charCodeAt(0).toString(16);
});
}
var QueryTextFields = Backbone.Model.extend({
initialize: function(data, options) {
},
......@@ -76,8 +90,7 @@ define(function(require) {
if (keyFieldValue) {
var key = keyFieldValue[1];
var field = keyFieldValue[2];
var value = keyFieldValue[3];
value = value.replace(/(\+|%20)/g, ' ');
var value = unquoteUrlValue(keyFieldValue[3]);
var impl = formNameMap[key];
if (impl) {
if (impl instanceof QueryTextField) {
......@@ -135,10 +148,10 @@ define(function(require) {
var serializedQuery = _.map(result, function(value, key) {
if (_.isArray(value)) {
return _.map(value, function(item, index) {
return key + '=' + item;
return key + '=' + quoteUrlValue(item);
}).join('&');
} else {
return key + '=' + value;
return key + '=' + quoteUrlValue(value);
}
}).join('&');
this.set('serializedQuery', serializedQuery);
......