Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

URL with % are throw URISyntaxException #40

Closed
wants to merge 6 commits into from

2 participants

@gnandiga

I fixed by replacing the right % character with %25(url encode value for %)

@lightbody
Owner

Unfortunately the pull request is a bit stale and won't merge automatically any longer. Sorry for not noticing it until now - feel free to ping the list if you issue one in the future. Can you re-submit so that it can merge nicely and I'll be sure to get to it sooner. Thanks!

@lightbody lightbody closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 9, 2012
  1. @gnandiga

    Added escape character functionality, so that double escapes dont com…

    gnandiga authored
    …e back with URISyntaxException
  2. @gnandiga

    Added escape character functionality, so that double escapes dont com…

    gnandiga authored
    …e back with URISyntaxException
  3. @gnandiga
  4. @gnandiga

    Fixed sun import classes

    gnandiga authored
  5. @gnandiga

    Chnaged from URI.getQuery to URI.getRawQuery as getQuery decodes as p…

    gnandiga authored
    …er the JVM and this converts certain characters into non-UTF-8 characters
Commits on Feb 14, 2012
  1. @gnandiga

    Basic import cleanup

    gnandiga authored
This page is out of date. Refresh to see the latest.
View
1  .gitignore
@@ -5,3 +5,4 @@ target
/.classpath
/.settings
/.project
+/.idea
View
6 pom.xml
@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>biz.neustar</groupId>
<artifactId>browsermob-proxy</artifactId>
- <version>2.0-beta-6-SNAPSHOT</version>
+ <version>2.0-beta-8-SNAPSHOT</version>
<name>BrowserMob Proxy</name>
<description>A programmatic HTTP/S designed for performance and functional testing</description>
<url>http://opensource.webmetrics.com/browsermob-proxy</url>
@@ -164,13 +164,13 @@
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
- <version>1.7.1</version>
+ <version>1.8.3</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
- <version>1.7.1</version>
+ <version>1.8.3</version>
</dependency>
<dependency>
View
32 src/main/java/org/browsermob/proxy/http/BrowserMobHttpClient.java
@@ -7,6 +7,7 @@
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.URLDecoder;
import java.util.Date;
import java.util.HashSet;
import java.util.HashMap;
@@ -316,9 +317,11 @@ public BrowserMobHttpRequest newHead(String url) {
}
}
- private URI makeUri(String url) throws URISyntaxException {
+ protected URI makeUri(String url) throws URISyntaxException {
// MOB-120: check for | character and change to correctly escaped %7C
- url = url.replace(" ", "%20");
+ url = changePercentEscapeCharacter(url);
+
+ url = url.replace(" ", "%20");
url = url.replace(">", "%3C");
url = url.replace("<", "%3E");
url = url.replace("#", "%23");
@@ -363,7 +366,19 @@ private URI makeUri(String url) throws URISyntaxException {
return uri;
}
- private RuntimeException reportBadURI(String url, String method) {
+ private String changePercentEscapeCharacter(String url)
+ {
+ Pattern hexDecimalPattern = Pattern.compile("%(%[A-Fa-f0-9]{1,2})");
+ Matcher hexDecimalMatcher = hexDecimalPattern.matcher(url);
+ url = hexDecimalMatcher.replaceAll("%25$1");
+
+ Pattern hexDecimalPattern2 = Pattern.compile("(%[A-Fa-f0-9]{1,2})%");
+ Matcher hexDecimalMatcher2 = hexDecimalPattern2.matcher(url);
+ url = hexDecimalMatcher2.replaceAll("$1%25");
+ return url;
+ }
+
+ private RuntimeException reportBadURI(String url, String method) {
if (this.har != null && harPageRef != null) {
HarEntry entry = new HarEntry(harPageRef);
entry.setTime(0);
@@ -511,11 +526,12 @@ private BrowserMobHttpResponse execute(BrowserMobHttpRequest req, int depth) {
if (this.har != null && harPageRef != null) {
har.getLog().addEntry(entry);
}
-
- String query = method.getURI().getQuery();
- if (query != null) {
- MultiMap<String> params = new MultiMap<String>();
- UrlEncoded.decodeTo(query, params, "UTF-8");
+
+ String query = method.getURI().getQuery();
+
+ if (query != null) {
+ MultiMap<String> params = new MultiMap<String>();
+ UrlEncoded.decodeTo(query, params, "UTF-8");
for (String k : params.keySet()) {
for (Object v : params.getValues(k)) {
entry.getRequest().getQueryString().add(new HarNameValuePair(k, (String) v));
View
37 src/test/java/org/browsermob/proxy/http/BrowserMobHttpClientTest.java
@@ -0,0 +1,37 @@
+package org.browsermob.proxy.http;
+
+import org.apache.commons.io.FileUtils;
+import org.eclipse.jetty.util.MultiMap;
+import org.eclipse.jetty.util.UrlEncoded;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.util.List;
+
+public class BrowserMobHttpClientTest
+{
+
+ @Test
+ public void verifyURI()
+ {
+
+ BrowserMobHttpClient client = new BrowserMobHttpClient();
+ try
+ {
+ String url = "http://example.com/cs/default.aspx?type=left&logo=0&bestdeal=1&pc=n&skin=001&pin=%3C%=pin%%3E&did=-1&txt=224273&target=_top";
+
+ client.makeUri(url);
+
+ client.makeUri("http://example.com/cs/default.aspx");
+ } catch (URISyntaxException e)
+ {
+ Assert.fail("Exception was not supposed to happen here: " + e.getMessage());
+ }
+ }
+
+}
View
1  src/test/resources/urls.txt
@@ -0,0 +1 @@
+http://cdn.api.twitter.com/1/urls/count.json?url=http%3A%2F%2Fwww.cruise.com%2Fblog%2Fpost%2FENJOY-THE-HOLIDAYS-AT-SEA-%E2%80%93-IT%E2%80%99S-NOT-TOO-LATE.aspx&callback=twttr.receiveCount
Something went wrong with that request. Please try again.