Apache Nutch is an extensible and scalable web crawler
NUTCH-620 BasicURLNormalizer should collapse runs of slashes with a single slash.
Andrzej Bialecki59695c9d079e
diff --git a/CHANGES.txt b/CHANGES.txtindex cd002fd07..51f5cca82 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -242,6 +242,9 @@ Unreleased changes (1.0-dev)88. NUTCH-598 - Remove deprecated use of ToolBase. Use generics in Hadoop API.(Emmanuel Joke, dogacan, ab)+89. NUTCH-620 - BasicURLNormalizer should collapse runs of slashes with a+ single slash. (Mark DeSpain via ab)+Release 0.9 - 2007-04-02diff --git a/src/plugin/urlnormalizer-basic/src/java/org/apache/nutch/net/urlnormalizer/basic/BasicURLNormalizer.java b/src/plugin/urlnormalizer-basic/src/java/org/apache/nutch/net/urlnormalizer/basic/BasicURLNormalizer.javaindex ccb5bfff3..29f55639d 100644--- a/src/plugin/urlnormalizer-basic/src/java/org/apache/nutch/net/urlnormalizer/basic/BasicURLNormalizer.java+++ b/src/plugin/urlnormalizer-basic/src/java/org/apache/nutch/net/urlnormalizer/basic/BasicURLNormalizer.java@@ -43,6 +43,7 @@ public class BasicURLNormalizer implements URLNormalizer {};private Rule relativePathRule = null;private Rule leadingRelativePathRule = null;+ private Rule adjacentSlashRule = null;private Configuration conf;@@ -64,6 +65,13 @@ public class BasicURLNormalizer implements URLNormalizer {compiler.compile("^(/\\.\\./)+", Perl5Compiler.READ_ONLY_MASK);leadingRelativePathRule.substitution = new Perl5Substitution("/");+ // this pattern tries to find spots like "xx//yy" in the url,+ // which could be replaced by a "/"+ adjacentSlashRule = new Rule();+ adjacentSlashRule.pattern = (Perl5Pattern)+ compiler.compile("/{2,}", Perl5Compiler.READ_ONLY_MASK);+ adjacentSlashRule.substitution = new Perl5Substitution("/");+} catch (MalformedPatternException e) {e.printStackTrace(LogUtil.getWarnStream(LOG));throw new RuntimeException(e);@@ -163,6 +171,13 @@ public class BasicURLNormalizer implements URLNormalizer {fileWorkCopy = Util.substitute(matcher, leadingRelativePathRule.pattern,leadingRelativePathRule.substitution, fileWorkCopy, 1);+++ // collapse adjacent slashes with "/"+ fileWorkCopy = Util.substitute+ (matcher, adjacentSlashRule.pattern,+ adjacentSlashRule.substitution, fileWorkCopy, 1);+newLen = fileWorkCopy.length();}diff --git a/src/plugin/urlnormalizer-basic/src/test/org/apache/nutch/net/urlnormalizer/basic/TestBasicURLNormalizer.java b/src/plugin/urlnormalizer-basic/src/test/org/apache/nutch/net/urlnormalizer/basic/TestBasicURLNormalizer.javaindex 4f7014f65..3bf289a9c 100644--- a/src/plugin/urlnormalizer-basic/src/test/org/apache/nutch/net/urlnormalizer/basic/TestBasicURLNormalizer.java+++ b/src/plugin/urlnormalizer-basic/src/test/org/apache/nutch/net/urlnormalizer/basic/TestBasicURLNormalizer.java@@ -90,12 +90,22 @@ public class TestBasicURLNormalizer extends TestCase {"http://foo.com/foo.html" );normalizeTest("http://foo.com/foo.foo/../foo.html","http://foo.com/foo.html" );+ normalizeTest("http://foo.com//aa/bb/foo.html",+ "http://foo.com/aa/bb/foo.html" );+ normalizeTest("http://foo.com/aa//bb/foo.html",+ "http://foo.com/aa/bb/foo.html" );+ normalizeTest("http://foo.com/aa/bb//foo.html",+ "http://foo.com/aa/bb/foo.html" );+ normalizeTest("http://foo.com//aa//bb//foo.html",+ "http://foo.com/aa/bb/foo.html" );+ normalizeTest("http://foo.com////aa////bb////foo.html",+ "http://foo.com/aa/bb/foo.html" );}private void normalizeTest(String weird, String normal) throws Exception {assertEquals(normal, normalizer.normalize(weird, URLNormalizers.SCOPE_DEFAULT));}-+public static void main(String[] args) throws Exception {new TestBasicURLNormalizer("test").testNormalizer();}