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:
Tim Schaub
2010-03-20 03:46:49 +00:00
parent 5038090d74
commit a5bb2b01b3

View File

@@ -266,7 +266,7 @@
}
function test_Util_getParameterString(t) {
t.plan( 5 );
t.plan(6);
var params = {
'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({'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
// list of the URL encoded strings
@@ -892,7 +894,7 @@
}
function test_Util_getParameters(t) {
t.plan(12);
t.plan(13);
t.eq(OpenLayers.Util.getParameters('http://www.example.com'), {},
"getParameters works when args = ''");
@@ -937,6 +939,19 @@
t.eq(OpenLayers.Util.getParameters('http://www.example.com?foo=bar%2Bone'),
{'foo': 'bar+one'},
"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&amp=&26#id"
};
var str = OpenLayers.Util.getParameterString(obj);
t.eq(OpenLayers.Util.getParameters("?" + str), obj, "round tripped parameters");
}