Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-1011 Remove duplicate slashes from URLs

Markus Jelsma116da8692cbd
diff --git a/CHANGES.txt b/CHANGES.txt
index 5ca9b648b..15971b3f3 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,8 @@ Nutch Change Log
Release 2.0 - Current Development
+* NUTCH-1011 Normalize duplicate slashes in URL's (markus)
+
* NUTCH-1013 Migrate RegexURLNormalizer from Apache ORO to java.util.regex (markus)
* NUTCH-1016 Strip UTF-8 non-character codepoints and add logging for SolrWriter (markus)
diff --git a/conf/regex-normalize.xml.template b/conf/regex-normalize.xml.template
index 5b82f6baa..95f755767 100644
--- a/conf/regex-normalize.xml.template
+++ b/conf/regex-normalize.xml.template
@@ -63,4 +63,10 @@
<substitution></substitution>
</regex>
+<!-- removes duplicate slashes -->
+<regex>
+ <pattern>(?&lt;!:)/{2,}</pattern>
+ <substitution>/</substitution>
+</regex>
+
</regex-normalize>
diff --git a/src/test/org/apache/nutch/net/TestURLNormalizers.java b/src/test/org/apache/nutch/net/TestURLNormalizers.java
index 7d2d58533..2d95b02aa 100644
--- a/src/test/org/apache/nutch/net/TestURLNormalizers.java
+++ b/src/test/org/apache/nutch/net/TestURLNormalizers.java
@@ -39,6 +39,15 @@ public class TestURLNormalizers extends TestCase {
} catch (MalformedURLException mue) {
fail(mue.toString());
}
+
+ // NUTCH-1011 - Get rid of superfluous slashes
+ try {
+ String normalizedSlashes = normalizers.normalize("http://www.example.org//path/to//somewhere.html", URLNormalizers.SCOPE_DEFAULT);
+ assertEquals(normalizedSlashes, "http://www.example.org/path/to/somewhere.html");
+ } catch (MalformedURLException mue) {
+ fail(mue.toString());
+ }
+
// check the order
int pos1 = -1, pos2 = -1;
URLNormalizer[] impls = normalizers.getURLNormalizers(URLNormalizers.SCOPE_DEFAULT);