mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-09-25 15:16:24 +00:00
HER-1998 - ExtractorHTML modified to parse html inside conditional comments. Still ignores normal comments
This commit is contained in:
@@ -114,7 +114,7 @@ public class ExtractorHTML extends ContentExtractor implements InitializingBean
|
||||
"(?is)<(?:((script[^>]*+)>.*?</script)" + // 1, 2
|
||||
"|((style[^>]*+)>.*?</style)" + // 3, 4
|
||||
"|(((meta)|(?:\\w{1,"+MAX_ELEMENT_REPLACE+"}))\\s+[^>]*+)" + // 5, 6, 7
|
||||
"|(!--.*?--))>"; // 8
|
||||
"|(!--(?!\\[if).*?--))>"; // 8
|
||||
|
||||
// version w/ problems with unclosed script tags
|
||||
// static final String RELEVANT_TAG_EXTRACTOR =
|
||||
|
||||
@@ -66,6 +66,7 @@ public class ExtractorHTMLTest extends StringExtractorTestBase {
|
||||
|
||||
"<img src=\"foo.gif\"> IMG",
|
||||
"http://www.archive.org/start/foo.gif",
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -379,5 +380,32 @@ public class ExtractorHTMLTest extends StringExtractorTestBase {
|
||||
assertTrue("outlinks should contain: "+expected,
|
||||
CollectionUtils.exists(curi.getOutLinks(),destinationsIsPredicate(expected)));
|
||||
}
|
||||
|
||||
/**
|
||||
* HER-1998
|
||||
* @throws URIException
|
||||
*/
|
||||
public void testConditionalComment1() throws URIException {
|
||||
CrawlURI curi = new CrawlURI(UURIFactory.getInstance("http://www.example.com/"));
|
||||
|
||||
CharSequence cs =
|
||||
"<!--[if IE 6]><img src=\"foo.gif\"><![endif]-->" +
|
||||
"<!--[if IE 6]><script src=\"foo.js\"><![endif]-->";
|
||||
|
||||
ExtractorHTML extractor = (ExtractorHTML)makeExtractor();
|
||||
extractor.extract(curi, cs);
|
||||
|
||||
Link[] links = curi.getOutLinks().toArray(new Link[0]);
|
||||
Arrays.sort(links);
|
||||
|
||||
String dest1 = "http://www.example.com/foo.gif";
|
||||
String dest2 = "http://www.example.com/foo.js";
|
||||
|
||||
assertEquals("outlink1 from conditional comment img src",dest1,
|
||||
links[0].getDestination().toString());
|
||||
assertEquals("outlink2 from conditional comment script src",dest2,
|
||||
links[1].getDestination().toString());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user