Skip to content

Commit

Permalink
glow.data.decodeUrl: Fixing for ; separator [#16 state:review]
Browse files Browse the repository at this point in the history
  • Loading branch information
jakearchibald committed Aug 3, 2009
1 parent 2d8eb5d commit 635e0e2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/data/data.js
Expand Up @@ -84,7 +84,7 @@
}

/*
PrivateMethod: _getType
PrivateMethod: _replaceSlashes
Callback function for glow.lang.replace to escape appropriate characters
Arguments:
Expand Down Expand Up @@ -214,7 +214,7 @@
}

var result = {};
var keyValues = text.split(TEXT.AND);
var keyValues = text.split(/[&;]/);

var thisPair, key, value;

Expand All @@ -223,8 +223,8 @@
if(thisPair.length != 2) {
throw new Error("glow.data.decodeUrl: cannot decode item");
} else {
key = decodeURIComponent(thisPair[0]);
value = decodeURIComponent(thisPair[1]);
key = glow.lang.trim( decodeURIComponent(thisPair[0]) );
value = glow.lang.trim( decodeURIComponent(thisPair[1]) );

switch (_getType(result[key])) {
case TYPES.ARRAY:
Expand Down
13 changes: 12 additions & 1 deletion test/glow/data/data.js
Expand Up @@ -117,7 +117,7 @@ t.test("glow.data.encodeUrl", function() {
});

t.test("glow.data.decodeUrl", function() {
t.expect(4);
t.expect(5);

var t1 = glow.data.decodeUrl("a=a&b=1");
t.equals([t1.a, t1.b].join(":"),
Expand All @@ -141,6 +141,17 @@ t.test("glow.data.decodeUrl", function() {
} catch(e) {
t.ok(true, "URLs must be well formed");
}

// http://glow-project.lighthouseapp.com/projects/33663-glow/tickets/16
// Ensure it works with ; seperators
var data = glow.data.decodeUrl("BBC-UID=abc123; foo=Domestic; bar=+acv+ba; helloworld=-99");
var obj = {
"BBC-UID": "abc123",
"foo": "Domestic",
"bar": "+acv+ba",
"helloworld": "-99"
}
t.isObj(data, obj, "Correct decoding with ;");
});


Expand Down

0 comments on commit 635e0e2

Please sign in to comment.