Making it so OpenLayers.Util.getParameters doesn't fail with improperly encoded query string parameter names or values. We expect parameter names and values to be encoded according to RFC 3986 (http://labs.apache.org/webarch/uri/rfc/rfc3986.html). However, there are cases where browsers will not use utf-8 character encoding in generating a URL. In these cases, the unescape function provides a fallback that tries to use the ISO Latin character set. This may not always be a good second assumption, but it is better than failing to load the library when the first assumption fails. r=ahocevar (closes #2821)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10771 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2010-09-17 16:48:11 +00:00
parent bb71632848
commit b8feb3c22e
2 changed files with 32 additions and 5 deletions
+14 -1
View File
@@ -1,5 +1,6 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<script>
var custom$ = function() {};
window.$ = custom$;
@@ -894,7 +895,7 @@
}
function test_Util_getParameters(t) {
t.plan(13);
t.plan(17);
t.eq(OpenLayers.Util.getParameters('http://www.example.com'), {},
"getParameters works when args = ''");
@@ -952,6 +953,18 @@
};
var str = OpenLayers.Util.getParameterString(obj);
t.eq(OpenLayers.Util.getParameters("?" + str), obj, "round tripped parameters");
// try some oddly encoded strings
var url = "http://example.com/?C%E9sar=C%E9sar+Ch%E1vez";
var obj = OpenLayers.Util.getParameters(url);
t.ok("César" in obj, "got proper key from C%E9sar");
t.eq(obj["César"], "César Chávez", "got proper value from C%E9sar+Ch%E1vez");
// try some properly encoded strings
var url = "http://example.com/?C%C3%A9sar=C%C3%A9sar+Ch%C3%A1vez";
var obj = OpenLayers.Util.getParameters(url);
t.ok("César" in obj, "got proper key from C%C3%A9sar");
t.eq(obj["César"], "César Chávez", "got proper value from C%E9sar+Ch%E1vez");
}