Skip to content
Permalink
Browse files

Merge branch 'master' of https://github.com/jOOQ/jOOX

  • Loading branch information...
lukaseder committed May 22, 2019
2 parents 64bd869 + 45af420 commit 06d2573c6ad9fb9e42ae7ca4baeb6be015623d53
@@ -11,7 +11,7 @@

<groupId>org.jooq</groupId>
<artifactId>joox-java-6</artifactId>
<version>1.6.1</version>
<version>1.6.2</version>
<packaging>bundle</packaging>

<name>jOOX</name>
@@ -50,6 +50,7 @@
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;


/**
@@ -103,6 +104,9 @@ static final DocumentFragment createContent(Document doc, String text) {
if (text != null && (text.contains("<") || text.contains("&"))) {
DocumentBuilder builder = JOOX.builder();

// [#162] Prevent log output
builder.setErrorHandler(new DefaultHandler());

try {

// [#128] Trimming will get rid of leading and trailing whitespace, which would
@@ -14,6 +14,7 @@
package org.joox.selector;

import java.util.List;
import java.util.regex.Pattern;

/**
* A utility class converting CSS selector expressions to XPath expressions.
@@ -30,6 +31,11 @@
*/
public final class CSS2XPath {

/**
* A selector pattern that can be evaluated using standard DOM API
*/
private final static Pattern SIMPLE_SELECTOR = Pattern.compile("[\\w\\-]+");

/**
* Convert a CSS selector expression to an XPath expression
*/
@@ -75,7 +81,15 @@ public static final String css2xpath(String css, boolean isRoot) {
break;
}

sb.append(s.getTagName());
// [#163] To stay on the safe side, we need namespace unaware XPath expressions here
// Do this only for actual tag names, not e.g. * or other special characters
if (SIMPLE_SELECTOR.matcher(s.getTagName()).matches())
sb.append("*[local-name() = '").append(s.getTagName()).append("']");
else
sb.append(s.getTagName());

// [#163] This would be an XPath 2.0 syntax, not supported by Java's built-in XPath libraries
// sb.append("*:").append(s.getTagName());

if (s.hasSpecifiers()) {
for (Specifier specifier : s.getSpecifiers()) {
@@ -2045,6 +2045,18 @@ public void testNamespacesMatchAPI() {
// TODO: restrict resulting elements to matching namespaces
}

@Test
public void testNamespacesSelectors() {
$ = $(xmlNamespacesDocument);

// [#107] Short circuiting find implementation
assertEquals(12, $.find("node").size());

// [#163] "Complex" selector
assertEquals(4, $.find("nested1 node").size());
assertEquals(8, $.find("nested1 node, nested2 node").size());
}

@Test
public void testNamespacesXPath() {
$ = $(xmlNamespacesDocument);
@@ -11,7 +11,7 @@

<groupId>org.jooq</groupId>
<artifactId>joox</artifactId>
<version>1.6.1</version>
<version>1.6.2</version>
<packaging>bundle</packaging>

<name>jOOX</name>
@@ -50,6 +50,7 @@
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;


/**
@@ -103,6 +104,9 @@ static final DocumentFragment createContent(Document doc, String text) {
if (text != null && (text.contains("<") || text.contains("&"))) {
DocumentBuilder builder = JOOX.builder();

// [#162] Prevent log output
builder.setErrorHandler(new DefaultHandler());

try {

// [#128] Trimming will get rid of leading and trailing whitespace, which would

0 comments on commit 06d2573

Please sign in to comment.
You can’t perform that action at this time.