Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

unescape fallback for malformed uri components #20

Open
wants to merge 3 commits into from

3 participants

@denisu

instead of just ignoring wrong encoded uri components, we should at least unescape them with the default javascript unescape function, which doesn't break on malformed encodings.

this fixes issues in a messed up iso-8859-1 environment.

Dennis unescape fallback for malformed uri components
instead of just ignoring wrong encoded uri components, we should at leas
t unescape them with the default javascript unescape function, which doe
sn't break on malformed encodings.
140ab27
@tj
Owner
tj commented

mind adding a test before I merge?

@denisu

sure :).

i also added a case to test if iso-8859-1 data is unescaped correctly. i am not sure if this is an issue we should care about though. if it doesn't belong there, leave it out.

@jonathanong

@denisu wanna rebase by any chance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 28, 2011
  1. unescape fallback for malformed uri components

    Dennis authored
    instead of just ignoring wrong encoded uri components, we should at leas
    t unescape them with the default javascript unescape function, which doe
    sn't break on malformed encodings.
Commits on Aug 29, 2011
  1. test for unescaping of non-utf8 encoded data

    Dennis authored
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 2 deletions.
  1. +1 −1  lib/querystring.js
  2. +6 −1 test/parse.test.js
View
2  lib/querystring.js
@@ -47,7 +47,7 @@ exports.parse = function(str){
try{
pair = decodeURIComponent(pair.replace(/\+/g, ' '));
} catch(e) {
- // ignore
+ pair = unescape(pair.replace(/\+/g, ' '));
}
var eql = pair.indexOf('=')
View
7 test/parse.test.js
@@ -140,8 +140,13 @@ module.exports = {
'test malformed uri': function(){
qs.parse('{%:%}').should.eql({ '{%:%}': '' });
qs.parse('foo=%:%}').should.eql({ 'foo': '%:%}' });
+ qs.parse('foo=%:%}%20').should.eql({ 'foo': '%:%} ' });
+ },
+
+ 'test unescaping of non-utf8 encoded data': function(){
+ qs.parse('foo=%E4%20bar').should.eql({ 'foo': String.fromCharCode('228') + ' bar' });
}
-
+
// 'test complex': function(){
// qs.parse('users[][name][first]=tj&users[foo]=bar')
// .should.eql({
Something went wrong with that request. Please try again.