Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-935 basicurlnormalizer removes unnecessary /./ in URLs

Julien Nioche02e18a5f7e77
diff --git a/CHANGES.txt b/CHANGES.txt
index 52a2fa6e4..e8e27ec7c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,8 @@ Nutch Change Log
Release 2.0 - Current Development
+* NUTCH-935 basicurlnormalizer removes unnecessary /./ in URLs
+
* NUTCH-912 MoreIndexingFilter does not parse docx and xlsx date formats (Markus Jelsma, jnioche)
* NUTCH-936 LanguageIdentifier should not set empty lang field on NutchDocument (Markus Jelsma via jnioche)
diff --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.java
index 8386b191e..2bf141f8f 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 currentPathRule = null;
private Rule adjacentSlashRule = null;
private Configuration conf;
@@ -65,6 +66,13 @@ public class BasicURLNormalizer implements URLNormalizer {
compiler.compile("^(/\\.\\./)+", Perl5Compiler.READ_ONLY_MASK);
leadingRelativePathRule.substitution = new Perl5Substitution("/");
+ // this pattern tries to find spots like "/./" in the url,
+ // which could be replaced by "/"
+ currentPathRule = new Rule();
+ currentPathRule.pattern = (Perl5Pattern)
+ compiler.compile("(/\\./)", Perl5Compiler.READ_ONLY_MASK);
+ currentPathRule.substitution = new Perl5Substitution("/");
+
// this pattern tries to find spots like "xx//yy" in the url,
// which could be replaced by a "/"
adjacentSlashRule = new Rule();
@@ -171,6 +179,11 @@ public class BasicURLNormalizer implements URLNormalizer {
fileWorkCopy = Util.substitute
(matcher, leadingRelativePathRule.pattern,
leadingRelativePathRule.substitution, fileWorkCopy, 1);
+
+ // remove unnecessary "/./"
+ fileWorkCopy = Util.substitute
+ (matcher, currentPathRule.pattern,
+ currentPathRule.substitution, fileWorkCopy, 1);
// collapse adjacent slashes with "/"
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.java
index 3bf289a9c..d93081626 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
@@ -60,6 +60,9 @@ public class TestBasicURLNormalizer extends TestCase {
// normalizeTest("http://foo.com/%66oo.html", "http://foo.com/foo.html");
// check that unnecessary "../" are removed
+
+ normalizeTest("http://foo.com/aa/./foo.html",
+ "http://foo.com/aa/foo.html" );
normalizeTest("http://foo.com/aa/../",
"http://foo.com/" );
normalizeTest("http://foo.com/aa/bb/../",
@@ -112,4 +115,5 @@ public class TestBasicURLNormalizer extends TestCase {
-}
+
+}
\ No newline at end of file