Adding tests for encoding & decoding URI components to avoid future regressions.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@10134 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
+17
-2
@@ -266,7 +266,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_Util_getParameterString(t) {
|
function test_Util_getParameterString(t) {
|
||||||
t.plan( 5 );
|
t.plan(6);
|
||||||
|
|
||||||
var params = {
|
var params = {
|
||||||
'foo': "bar",
|
'foo': "bar",
|
||||||
@@ -276,6 +276,8 @@
|
|||||||
t.eq( OpenLayers.Util.getParameterString(params), "foo=bar&chicken=1.5", "getParameterString returns correctly");
|
t.eq( OpenLayers.Util.getParameterString(params), "foo=bar&chicken=1.5", "getParameterString returns correctly");
|
||||||
t.eq( OpenLayers.Util.getParameterString({'a:':'b='}), "a%3A=b%3D", "getParameterString returns correctly with non-ascii keys/values");
|
t.eq( OpenLayers.Util.getParameterString({'a:':'b='}), "a%3A=b%3D", "getParameterString returns correctly with non-ascii keys/values");
|
||||||
|
|
||||||
|
t.eq(OpenLayers.Util.getParameterString({chars: "~!*()'"}), "chars=~!*()'", "~!*()' are unreserved or have no reserved purpose in a URI component");
|
||||||
|
|
||||||
|
|
||||||
// Parameters which are a list should end up being a comma-seperated
|
// Parameters which are a list should end up being a comma-seperated
|
||||||
// list of the URL encoded strings
|
// list of the URL encoded strings
|
||||||
@@ -892,7 +894,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_Util_getParameters(t) {
|
function test_Util_getParameters(t) {
|
||||||
t.plan(12);
|
t.plan(13);
|
||||||
|
|
||||||
t.eq(OpenLayers.Util.getParameters('http://www.example.com'), {},
|
t.eq(OpenLayers.Util.getParameters('http://www.example.com'), {},
|
||||||
"getParameters works when args = ''");
|
"getParameters works when args = ''");
|
||||||
@@ -937,6 +939,19 @@
|
|||||||
t.eq(OpenLayers.Util.getParameters('http://www.example.com?foo=bar%2Bone'),
|
t.eq(OpenLayers.Util.getParameters('http://www.example.com?foo=bar%2Bone'),
|
||||||
{'foo': 'bar+one'},
|
{'foo': 'bar+one'},
|
||||||
"getParameters works with properly encoded + character");
|
"getParameters works with properly encoded + character");
|
||||||
|
|
||||||
|
// Let's do some round tripping to make it harder to introduce regressions
|
||||||
|
var obj = {
|
||||||
|
"a key": "a value with spaces (and +)",
|
||||||
|
"see%2B%2B": "C++",
|
||||||
|
"C++": "see%2B%2B",
|
||||||
|
"~%257E": "+%252B",
|
||||||
|
"who?": "me?",
|
||||||
|
"#yes": "#you",
|
||||||
|
"url": "http://example.com:80/?question=%3F&hash=%23&=&26#id"
|
||||||
|
};
|
||||||
|
var str = OpenLayers.Util.getParameterString(obj);
|
||||||
|
t.eq(OpenLayers.Util.getParameters("?" + str), obj, "round tripped parameters");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user