From a5bb2b01b394b369ad6f2633dbc197e4d34ff764 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sat, 20 Mar 2010 03:46:49 +0000 Subject: [PATCH] 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 --- tests/Util.html | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/Util.html b/tests/Util.html index 62885a3bee..a79ff2eab9 100644 --- a/tests/Util.html +++ b/tests/Util.html @@ -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&=&26#id" + }; + var str = OpenLayers.Util.getParameterString(obj); + t.eq(OpenLayers.Util.getParameters("?" + str), obj, "round tripped parameters"); }