You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stormcrawler.apache.org by jn...@apache.org on 2026/04/01 07:25:50 UTC
(stormcrawler) 01/01: Add XPath JSoup filter tests and make lowercaseElementNames public
This is an automated email from the ASF dual-hosted git repository.
jnioche pushed a commit to branch add-lowercase-element-names-test
in repository https://gitbox.apache.org/repos/asf/stormcrawler.git
commit c3391041656355fc5b4d3e7ccf39c7e3365d8629
Author: Julien Nioche <ju...@digitalpebble.com>
AuthorDate: Tue Mar 31 09:45:05 2026 +0100
Add XPath JSoup filter tests and make lowercaseElementNames public
Tests cover attribute extraction (/@attr), tidyText(), allText(),
html() functions, uppercase element name handling, fallback expression
logic, and the lowercaseElementNames() utility method.
Co-Authored-By: Claude Opus 4.6 <no...@anthropic.com>
---
.../java/org/apache/stormcrawler/jsoup/XPathFilter.java | 2 +-
.../org/apache/stormcrawler/jsoup/JSoupFiltersTest.java | 17 +++++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/core/src/main/java/org/apache/stormcrawler/jsoup/XPathFilter.java b/core/src/main/java/org/apache/stormcrawler/jsoup/XPathFilter.java
index d4558319..775ce6f6 100644
--- a/core/src/main/java/org/apache/stormcrawler/jsoup/XPathFilter.java
+++ b/core/src/main/java/org/apache/stormcrawler/jsoup/XPathFilter.java
@@ -92,7 +92,7 @@ public class XPathFilter extends AbstractConfigurable implements JSoupFilter {
* Lowercases element names in an XPath expression to match JSoup's normalized tag names. For
* example, {@code //SPAN[@class="concept"]} becomes {@code //span[@class="concept"]}.
*/
- static String lowercaseElementNames(String xpath) {
+ public static String lowercaseElementNames(String xpath) {
return ELEMENT_NAME
.matcher(xpath)
.replaceAll(m -> m.group().toLowerCase(java.util.Locale.ROOT));
diff --git a/core/src/test/java/org/apache/stormcrawler/jsoup/JSoupFiltersTest.java b/core/src/test/java/org/apache/stormcrawler/jsoup/JSoupFiltersTest.java
index c95905ab..a301e9f4 100644
--- a/core/src/test/java/org/apache/stormcrawler/jsoup/JSoupFiltersTest.java
+++ b/core/src/test/java/org/apache/stormcrawler/jsoup/JSoupFiltersTest.java
@@ -155,4 +155,21 @@ class JSoupFiltersTest extends ParsingTester {
Assertions.assertNotNull(fallback, "Fallback expression should have matched");
Assertions.assertTrue(fallback.contains("Main Title"));
}
+
+ @Test
+ void testLowercaseElementNames() {
+ Assertions.assertEquals(
+ "//span[@class=\"concept\"]",
+ XPathFilter.lowercaseElementNames("//SPAN[@class=\"concept\"]"));
+ Assertions.assertEquals(
+ "//meta[@name=\"keywords\"]/@content",
+ XPathFilter.lowercaseElementNames("//META[@name=\"keywords\"]/@content"));
+ Assertions.assertEquals(
+ "//*[@class=\"x\"]",
+ XPathFilter.lowercaseElementNames("//*[@class=\"x\"]"));
+ Assertions.assertEquals(
+ "//div/span/a[@href]",
+ XPathFilter.lowercaseElementNames("//DIV/SPAN/A[@href]"));
+ Assertions.assertEquals("//title", XPathFilter.lowercaseElementNames("//title"));
+ }
}