Skip to content
Browse files

fixing crashing of URI.decodeQuery() on malformed input - closes #87,…

… closes #92
  • Loading branch information...
1 parent a655011 commit fd8ee89a024698986ebef57393fcedbe22631616 @rodneyrehm rodneyrehm committed
Showing with 22 additions and 1 deletion.
  1. +1 −0 README.md
  2. +9 −1 src/URI.js
  3. +12 −0 test/test.js
View
1 README.md
@@ -209,6 +209,7 @@ URI.js is published under the [MIT license](http://www.opensource.org/licenses/m
### `[dev-version]` (master branch) ###
+* fixing crashing of `URI.decodeQuery()` on malformed input - now returns original undecoded data - ([Issue #87](https://github.com/medialize/URI.js/issues/87), [Issue #92](https://github.com/medialize/URI.js/issues/92))
* fixing build tool - ([Issue #83](https://github.com/medialize/URI.js/issues/83))
* fixing for-loop to make closure compiler happy - ([Issue #93](https://github.com/medialize/URI.js/issues/93))
* adding [`URI.noConflict()`](http://medialize.github.io/URI.js/docs.html#static-noConflict) - ([Issue #84](https://github.com/medialize/URI.js/issue/84))
View
10 src/URI.js
@@ -301,7 +301,15 @@ URI.encodeQuery = function(string) {
return URI.encode(string + "").replace(/%20/g, '+');
};
URI.decodeQuery = function(string) {
- return URI.decode((string + "").replace(/\+/g, '%20'));
+ try {
+ return URI.decode((string + "").replace(/\+/g, '%20'));
+ } catch(e) {
+ // we're not going to mess with weird encodings,
+ // give up and return the undecoded original string
+ // see https://github.com/medialize/URI.js/issues/87
+ // see https://github.com/medialize/URI.js/issues/92
+ return string;
+ }
};
URI.recodePath = function(string) {
var segments = (string + "").split('/');
View
12 test/test.js
@@ -1196,6 +1196,18 @@ test("iso8859", function() {
u.unicode();
equal(u.path(), "/%C3%A4.html", 'convert unicode');
});
+test("bad charset in QueryString", function() {
+ var uri = new URI("http://www.google.com.hk/search?q=pennytel%20downloads&sa=%20%CB%D1%20%CB%F7%20&forid=1&prog=aff&ie=GB2312&oe=GB2312&safe=active&source=sdo_sb_html&hl=zh-CN");
+ var data = uri.query(true);
+
+ equal(data.sa, "%20%CB%D1%20%CB%F7%20", 'undecodable value returned');
+ equal(data.forid, "1", 'decodable value returned');
+
+ uri.normalizeQuery();
+ data = uri.query(true);
+ equal(data.sa, "%20%CB%D1%20%CB%F7%20", 'undecodable value returned');
+ equal(data.forid, "1", 'decodable value returned');
+});
module("Encoding");
test("encodeReserved", function() {

0 comments on commit fd8ee89

Please sign in to comment.
Something went wrong with that request. Please try again.