Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hmottestad committed Dec 8, 2024
1 parent 44ee3c5 commit 4d441e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,19 @@ public static boolean isValidLocalName(String name) {

for (int i = 1; i < name.length(); i++) {
if (!isNameChar(name.charAt(i))) {

// PLX
if (name.charAt(i) == '%') {
continue;
} else if (name.charAt(i) == '\\') {
if (i + 1 < name.length() && isPN_LOCAL_ESC(name.substring(i, i + 2))) {
i++;
continue;
} else {
return false;
}
}

return false;
}

Expand Down Expand Up @@ -341,7 +354,7 @@ private static boolean isNameStartChar(int codePoint) {
* @return <code>true</code> if the supplied code point represents a valid name char, <code>false</code> otherwise.
*/
private static boolean isNameChar(int codePoint) {
return isPN_CHARS(codePoint) || codePoint == '.' || codePoint == ':' | codePoint == '\\' || codePoint == '%';
return isPN_CHARS(codePoint) || codePoint == '.' || codePoint == ':';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Arrays;

import org.eclipse.rdf4j.common.text.ASCIIUtil;
import org.eclipse.rdf4j.model.util.URIUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -366,41 +367,7 @@ public static boolean isPN_LOCAL_ESC(String name) {
}

public static boolean isPN_LOCAL(String name) {
// Empty names are legal
if (name.isEmpty()) {
return true;
}

if (!isPN_CHARS_U(name.charAt(0)) && name.charAt(0) != ':' && !ASCIIUtil.isNumber(name.charAt(0))
&& !isPLX_START(name)) {
logger.debug("PN_LOCAL was not valid (start characters invalid) i=" + 0 + " nextchar="
+ name.charAt(0) + " name=" + name);
return false;
}

if (!isNameStartChar(name.charAt(0))) {
logger.debug("name was not valid (start character invalid) i=" + 0 + " nextchar=" + name.charAt(0)
+ " name=" + name);
return false;
}

for (int i = 1; i < name.length(); i++) {
if (!isNameChar(name.charAt(i))) {
logger.debug("name was not valid (intermediate character invalid) i=" + i + " nextchar="
+ name.charAt(i) + " name=" + name);
return false;
}

// Check if the percent encoding was less than two characters from the
// end of the prefix, in which case it is invalid
if (name.charAt(i) == '%' && (name.length() - i) < 3) {
logger.debug("name was not valid (short percent escape) i=" + i + " nextchar=" + name.charAt(i)
+ " name=" + name);
return false;
}
}

return true;
return URIUtil.isValidLocalName(name);
}

// public static boolean isLegalName(String name) {
Expand Down

0 comments on commit 4d441e0

Please sign in to comment.