Permalink
Browse files

Merge pull request #690 from tf/upload-rights-plus-signs

Improve special character handling in formDataUtils
  • Loading branch information...
2 parents 3ab9bc3 + bbb4a18 commit 2450064d3205680b79c49eee3af5181d70bb77ba @tf tf committed on GitHub Dec 28, 2016
@@ -7,9 +7,11 @@ pageflow.formDataUtils = {
},
fromObject: function(object) {
- return _(decodeURIComponent($.param(object)).split('&')).reduce(function(result, param) {
+ var queryString = $.param(object).replace(/\+/g, '%20');
+
+ return _(queryString.split('&')).reduce(function(result, param) {
var pair = param.split('=');
- result[pair[0]] = pair[1];
+ result[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
return result;
}, {});
@@ -17,6 +17,20 @@ describe('formDataUtils', function() {
'some[deeply][nested]': 'data'
});
});
+
+ it('handles spaces, +, = and & signs correctly', function() {
+ var object = {
+ some: {
+ value: '1 + 1 = 2 & a',
+ }
+ };
+
+ var result = pageflow.formDataUtils.fromObject(object);
+
+ expect(result).to.eql({
+ 'some[value]': '1 + 1 = 2 & a',
+ });
+ });
});
describe('fromModel', function() {

0 comments on commit 2450064

Please sign in to comment.