Apache Nutch is an extensible and scalable web crawler
NUTCH-436 resolved. Fixed behavior of urls with param (i.e. ;xxxx) information. Finally found workaround for problems that I was experiencing with EOL characters.
Dennis Kubesd039a1384a54
diff --git a/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/DOMContentUtils.java b/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/DOMContentUtils.javaindex 2ac60aa1d..a8f4d173a 100644--- a/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/DOMContentUtils.java+++ b/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/DOMContentUtils.java@@ -282,6 +282,51 @@ public class DOMContentUtils {return false;}++ /**+ * Handles cases where the url param information is encoded into the base+ * url as opposed to the target.+ * <p>+ * If the taget contains params (i.e. ';xxxx') information then the target+ * params information is assumed to be correct and any base params information+ * is ignored. If the base contains params information but the tareget does+ * not, then the params information is moved to the target allowing it to be+ * correctly determined by the java.net.URL class.+ *+ * @param base The base URL.+ * @param target The target path from the base URL.+ *+ * @return URL A URL with the params information correctly encoded.+ *+ * @throws MalformedURLException If the url is not a well formed URL.+ */+ private URL fixEmbeddedParams(URL base, String target)+ throws MalformedURLException{++ // the target contains params information or the base doesn't then no+ // conversion necessary, return regular URL+ if (target.indexOf(';') >= 0 || base.toString().indexOf(';') == -1) {+ return new URL(base, target);+ }++ // get the base url and it params information+ String baseURL = base.toString();+ int startParams = baseURL.indexOf(';');+ String params = baseURL.substring(startParams);++ // if the target has a query string then put the params information after+ // any path but before the query string, otherwise just append to the path+ int startQS = target.indexOf('?');+ if (startQS >= 0) {+ target = target.substring(0, startQS) + params ++ target.substring(startQS);+ }+ else {+ target += params;+ }++ return new URL(base, target);+ }/*** This method finds all anchors below the supplied DOM@@ -333,7 +378,9 @@ public class DOMContentUtils {}if (target != null && !noFollow && !post)try {- URL url = new URL(base, target);++ URL url = (base.toString().indexOf(';') > 0) ?+ fixEmbeddedParams(base, target) : new URL(base, target);outlinks.add(new Outlink(url.toString(),linkText.toString().trim(), conf));} catch (MalformedURLException e) {diff --git a/src/plugin/parse-html/src/test/org/apache/nutch/parse/html/TestDOMContentUtils.java b/src/plugin/parse-html/src/test/org/apache/nutch/parse/html/TestDOMContentUtils.javaindex 26c7f7a93..45a4d99c3 100644--- a/src/plugin/parse-html/src/test/org/apache/nutch/parse/html/TestDOMContentUtils.java+++ b/src/plugin/parse-html/src/test/org/apache/nutch/parse/html/TestDOMContentUtils.java@@ -134,6 +134,20 @@ public class TestDOMContentUtils extends TestCase {+ "<input type=submit><p>test1</p></form>"+ "<form method='GET' action='/dummy.jsp'><input type=text>"+ "<input type=submit><p>test2</p></form></body></html>"),+ new String("<html><head><title> title </title>"+ + "</head><body>"+ + "<a href=\";x\">anchor1</a>"+ + "<a href=\"g;x\">anchor2</a>"+ + "<a href=\"g;x?y#s\">anchor3</a>"+ + "</body></html>"),+ new String("<html><head><title> title </title>"+ + "</head><body>"+ + "<a href=\"g\">anchor1</a>"+ + "<a href=\"g?y#s\">anchor2</a>"+ + "<a href=\"?y=1\">anchor3</a>"+ + "<a href=\"?y=1#s\">anchor4</a>"+ + "<a href=\"?y=1;somethingelse\">anchor5</a>"+ + "</body></html>"),};private static int SKIP = 9;@@ -149,6 +163,8 @@ public class TestDOMContentUtils extends TestCase {"http://www.nutch.org//","http://www.nutch.org/","http://www.nutch.org/",+ "http://www.nutch.org/",+ "http://www.nutch.org/;something"};private static final DocumentFragment testDOMs[]=@@ -173,7 +189,9 @@ public class TestDOMContentUtils extends TestCase {+ "End this madness ! . . . .","ignore ignore","test1 test2",- "test1 test2"+ "test1 test2",+ "title anchor1 anchor2 anchor3",+ "title anchor1 anchor2 anchor3 anchor4 anchor5"};private static final String[] answerTitle= {@@ -186,7 +204,9 @@ public class TestDOMContentUtils extends TestCase {"my title","","",- ""+ "",+ "title",+ "title"};// note: should be in page-order@@ -258,6 +278,18 @@ public class TestDOMContentUtils extends TestCase {new Outlink("http://www.nutch.org/dummy.jsp", "test2", conf),},{+ },+ {+ new Outlink("http://www.nutch.org/;x", "anchor1", conf),+ new Outlink("http://www.nutch.org/g;x", "anchor2", conf),+ new Outlink("http://www.nutch.org/g;x?y#s", "anchor3", conf)+ },+ {+ new Outlink("http://www.nutch.org/g;something", "anchor1", conf),+ new Outlink("http://www.nutch.org/g;something?y#s", "anchor2", conf),+ new Outlink("http://www.nutch.org/;something?y=1", "anchor3", conf),+ new Outlink("http://www.nutch.org/;something?y=1#s", "anchor4", conf),+ new Outlink("http://www.nutch.org/?y=1;somethingelse", "anchor5", conf)}};