[jscover] 52/69: Decode URL path for proxy mode

Sylvestre Ledru sylvestre at moszumanska.debian.org
Fri Aug 22 05:54:07 UTC 2014


This is an automated email from the git hooks/post-receive script.

sylvestre pushed a commit to branch master
in repository jscover.

commit bac4ffe30e911a75379b9fdbd9283b2122ffea18
Author: tntim96 <tntim96 at gmail.com>
Date:   Sat Jul 26 15:24:01 2014 +1000

    Decode URL path for proxy mode
---
 History.md                                           |  4 ++++
 src/main/java/jscover/server/HttpRequest.java        | 16 ++++++++++------
 src/main/java/jscover/util/UriFileTranslatorReg.java |  4 ----
 src/test/java/jscover/server/HttpRequestTest.java    |  3 ++-
 4 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/History.md b/History.md
index 51e7055..5e5fb52 100644
--- a/History.md
+++ b/History.md
@@ -1,3 +1,7 @@
+1.0.14 / 2014-??-??
+==================
+  * Decode URI in proxy mode
+
 1.0.13 / 2014-07-08
 ==================
   * Fix Java 5 compatibility (https://github.com/tntim96/JSCover/issues/150)
diff --git a/src/main/java/jscover/server/HttpRequest.java b/src/main/java/jscover/server/HttpRequest.java
index e940fb2..ecfec6d 100644
--- a/src/main/java/jscover/server/HttpRequest.java
+++ b/src/main/java/jscover/server/HttpRequest.java
@@ -367,13 +367,9 @@ public class HttpRequest {
         this.headers = headers;
         try {
             this.url = new URL(path);
-            this.path = url.getPath();
+            this.path = urlDecode(url.getPath());
         } catch (MalformedURLException e) {
-            try {
-                path = URLDecoder.decode(path, Charset.defaultCharset().name());
-            } catch (UnsupportedEncodingException e1) {
-                throw new RuntimeException(e1);
-            }
+            path = urlDecode(path);
             int index = path.indexOf("?");
             if (index > 0)
                 path = path.substring(0, index);
@@ -381,6 +377,14 @@ public class HttpRequest {
         }
     }
 
+    public static String urlDecode(String path) {
+        try {
+            return URLDecoder.decode(path, Charset.defaultCharset().name());
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
     public String getPath() {
         return path;
     }
diff --git a/src/main/java/jscover/util/UriFileTranslatorReg.java b/src/main/java/jscover/util/UriFileTranslatorReg.java
index c03f4b7..82542fc 100644
--- a/src/main/java/jscover/util/UriFileTranslatorReg.java
+++ b/src/main/java/jscover/util/UriFileTranslatorReg.java
@@ -360,10 +360,6 @@ public class UriFileTranslatorReg implements UriFileTranslator {
         return pattern;
     }
 
-    public String getReplacement() {
-        return replacement;
-    }
-
     public String convertUriToFile(String uri) {
         String filePath = pattern.matcher(uri).replaceAll(replacement);
         logger.log(Level.FINE, "Translated path from ''{0}'' to ''{1}''", new Object[]{uri, filePath});
diff --git a/src/test/java/jscover/server/HttpRequestTest.java b/src/test/java/jscover/server/HttpRequestTest.java
index c994da2..d20cd6d 100644
--- a/src/test/java/jscover/server/HttpRequestTest.java
+++ b/src/test/java/jscover/server/HttpRequestTest.java
@@ -431,6 +431,8 @@ public class HttpRequestTest {
         assertThat(new HttpRequest("test.js", null, null, 0, null).getRelativePath(), equalTo("test.js"));
         assertThat(new HttpRequest("/test.js", null, null, 0, null).getRelativePath(), equalTo("test.js"));
         assertThat(new HttpRequest("/js/test.js", null, null, 0, null).getRelativePath(), equalTo("js/test.js"));
+        assertThat(new HttpRequest("/js/a%20b.js", null, null, 0, null).getRelativePath(), equalTo("js/a b.js"));
+        assertThat(new HttpRequest("http://localhost/js/a%20b.js", null, null, 0, null).getRelativePath(), equalTo("js/a b.js"));
     }
 
     @Test
@@ -455,5 +457,4 @@ public class HttpRequestTest {
         assertThat(httpRequest.getOutputStream(), sameInstance(os));
         assertThat(httpRequest.getPostIndex(), sameInstance(postIndex));
     }
-
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jscover.git



More information about the pkg-java-commits mailing list