Being liberal in what we accept in query strings. A properly encoded '+' should be '%2B' in a URI component. A properly encoded ' ' (space) should be '%20'. When we encounter a '+', we can safely replace it with ' ' before properly decoding the remainder of the component. This follows the convention that '+' is used widely to represent a space in a URL. r=bartvde (closes #2527)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@10133 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -979,8 +979,8 @@ OpenLayers.Util.getParameters = function(url) {
|
||||
var key = decodeURIComponent(keyValue[0]);
|
||||
var value = keyValue[1] || ''; //empty string if no value
|
||||
|
||||
//decode individual values
|
||||
value = decodeURIComponent(value).split(",");
|
||||
//decode individual values (being liberal by replacing "+" with " ")
|
||||
value = decodeURIComponent(value.replace(/\+/g, " ")).split(",");
|
||||
|
||||
//if there's only one value, do not return as array
|
||||
if (value.length == 1) {
|
||||
|
||||
@@ -892,7 +892,7 @@
|
||||
}
|
||||
|
||||
function test_Util_getParameters(t) {
|
||||
t.plan(9);
|
||||
t.plan(12);
|
||||
|
||||
t.eq(OpenLayers.Util.getParameters('http://www.example.com'), {},
|
||||
"getParameters works when args = ''");
|
||||
@@ -922,6 +922,22 @@
|
||||
var url = "http://example.com/path?key=" + encoded; // this is a properly encoded URL
|
||||
var params = OpenLayers.Util.getParameters(url);
|
||||
t.eq(params.key, value, "a properly encoded value of '%20' is properly decoded");
|
||||
|
||||
/**
|
||||
* IETF RFC 2396 (http://www.ietf.org/rfc/rfc2396.txt) says spaces
|
||||
* should be encoded as "%20". However, the "+" is used widely to
|
||||
* indicate a space in a URL.
|
||||
*/
|
||||
t.eq(OpenLayers.Util.getParameters('http://www.example.com?foo=bar+one'),
|
||||
{'foo': 'bar one'},
|
||||
"getParameters works with + instead of %20 in values");
|
||||
t.eq(OpenLayers.Util.getParameters('http://www.example.com?foo=bar%20one'),
|
||||
{'foo': 'bar one'},
|
||||
"getParameters works with properly encoded space character");
|
||||
t.eq(OpenLayers.Util.getParameters('http://www.example.com?foo=bar%2Bone'),
|
||||
{'foo': 'bar+one'},
|
||||
"getParameters works with properly encoded + character");
|
||||
|
||||
}
|
||||
|
||||
function test_Util_getArgs(t) {
|
||||
|
||||
Reference in New Issue
Block a user