Skip to content

Commit

Permalink
Accept fragments containing characters (),. such as the ones found in
Browse files Browse the repository at this point in the history
JavaDoc
  • Loading branch information
ppalaga committed Jan 18, 2025
1 parent 23da95c commit 97af9c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Pattern;

import org.jboss.logging.Logger;
import org.jsoup.Connection.Method;
Expand Down Expand Up @@ -41,6 +42,8 @@ public static LinkValidator defaultValidator() {
static class LinkValidatorImpl implements LinkValidator {
private static final Logger log = Logger.getLogger(AntorAssured.class);

private static final Pattern JAVADOC_FRAGMENT_CHARS = Pattern.compile("[\\(\\)\\,\\.]");

/** JSoup documents by fragment-less URI */
private final Map<String, CacheEntry> documents = new ConcurrentHashMap<>();
/** Locks by fragment-less URI */
Expand Down Expand Up @@ -128,6 +131,15 @@ public ValidationResult validate(Link link) {

/* Find the fragment */
final Document doc = entry.document;

if (JAVADOC_FRAGMENT_CHARS.matcher(fragment).find()) {
/* Those chars are illegal in CSS selectors, so Tagsoup will fail at parsing the selector */
final String id = fragment.substring(1);
if (doc.getElementById(id) != null) {
return logAndReturn(uri, ValidationResult.valid(link));
}
}

try {
Elements foundElems = doc.select(fragment);
if (foundElems.isEmpty()) {
Expand All @@ -140,7 +152,7 @@ public ValidationResult validate(Link link) {
return logAndReturn(uri, result);
}
} catch (SelectorParseException e) {
log.error("Bad fragment: fragment", e);
log.error("Bad fragment: " + fragment + " in URI " + link.originalUri(), e);
throw e;
}
} finally {
Expand Down
1 change: 1 addition & 0 deletions docs/modules/ROOT/pages/test-page.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ Some valid links:

* https://quarkus.io/guides/building-native-image#prerequisites[good fragment]
* {test-link-quarkus-docs-base}/getting-started[link with an AsciiDoc attribute on line 21]
* https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/Duration.html#parse(java.lang.CharSequence)[Bad CSS selector, but still a good fragment]

0 comments on commit 97af9c7

Please sign in to comment.