Repository: crawljax/crawljax
Issue: Missing URL Parameter

Hi,
There is a issue with this configuration:

CrawljaxConfigurationBuilder builder = 
CrawljaxConfiguration.builderFor("http://site.com/page.aspx?q=biography")
.setBrowserConfig(new BrowserConfiguration(BrowserType.FIREFOX, 1))
.setProxyConfig(ProxyConfiguration.manualProxyOn("web-proxy", 8080))
.setBasicAuth("$iapsearch001", "run.sat.hot-287");

As you can see the URL is:
http://site.com/page.aspx?q=biography
and I have a basic Authentication.
That combination, for any reason when the Crawljax start crawling the URL is updated by http://site.com/page.aspx, as you can see the query parameter is missing :(

Tested on 3.4 and 3.5

Regards


Changed files:
core/src/main/java/com/crawljax/core/configuration/CrawljaxConfiguration.java
core/src/test/java/com/crawljax/core/configuration/CrawljaxConfigurationBuilderTest.java

diff --git a/core/src/main/java/com/crawljax/core/configuration/CrawljaxConfiguration.java b/core/src/main/java/com/crawljax/core/configuration/CrawljaxConfiguration.java
index 869887cd..f8ec5141 100644
--- a/core/src/main/java/com/crawljax/core/configuration/CrawljaxConfiguration.java
+++ b/core/src/main/java/com/crawljax/core/configuration/CrawljaxConfiguration.java
@@ -49,10 +49,8 @@ public class CrawljaxConfiguration {
 			try {
 				String encodedUsername = URLEncoder.encode(username, "UTF-8");
 				String encodedPassword = URLEncoder.encode(password, "UTF-8");
-				config.url = URI.create(config.url.getScheme()
-				  + "://" + encodedUsername
-				  + ":" + encodedPassword + "@" + config.url.getAuthority()
-				  + config.url.getPath());
+				String hostPrefix = encodedUsername + ":" + encodedPassword + "@";
+				config.url = URI.create(config.url.toString().replaceFirst("://", "://" + hostPrefix));
 			}
 			catch (UnsupportedEncodingException e) {
 				throw new CrawljaxException("Could not parse the username/password to a URL", e);
diff --git a/core/src/test/java/com/crawljax/core/configuration/CrawljaxConfigurationBuilderTest.java b/core/src/test/java/com/crawljax/core/configuration/CrawljaxConfigurationBuilderTest.java
index 75256930..73f63fa0 100644
--- a/core/src/test/java/com/crawljax/core/configuration/CrawljaxConfigurationBuilderTest.java
+++ b/core/src/test/java/com/crawljax/core/configuration/CrawljaxConfigurationBuilderTest.java
@@ -6,9 +6,9 @@ import static org.junit.Assert.assertThat;
 import java.io.File;
 import java.util.concurrent.TimeUnit;
 
-import org.junit.Test;
-
 import com.crawljax.core.configuration.CrawljaxConfiguration.CrawljaxConfigurationBuilder;
+import org.hamcrest.core.Is;
+import org.junit.Test;
 
 public class CrawljaxConfigurationBuilderTest {
 
@@ -49,4 +49,14 @@ public class CrawljaxConfigurationBuilderTest {
 		testBuilder().setOutputDirectory(file).build();
 	}
 
+
+	@Test
+	public void whenSpecifyingBasicAuthTheUrlShouldBePreserved() {
+		String url = "https://example.com/test/?a=b#anchor";
+		CrawljaxConfiguration conf = CrawljaxConfiguration.builderFor(url)
+				.setBasicAuth("username", "password")
+				.build();
+		assertThat(conf.getUrl().toString(), Is.is("https://username:password@example.com/test/?a=b#anchor"));
+	}
+
 }