Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/java/graphql/Assert.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Collection;
import java.util.function.Supplier;
import java.util.regex.Pattern;

import static java.lang.String.format;

Expand Down Expand Up @@ -100,6 +101,8 @@ public static void assertFalse(boolean condition) {

private static final String invalidNameErrorMessage = "Name must be non-null, non-empty and match [_A-Za-z][_0-9A-Za-z]* - was '%s'";

private static final Pattern validNamePattern = Pattern.compile("[_A-Za-z][_0-9A-Za-z]*");

/**
* Validates that the Lexical token name matches the current spec.
* currently non null, non empty,
Expand All @@ -108,7 +111,7 @@ public static void assertFalse(boolean condition) {
* @return the name if valid, or AssertException if invalid.
*/
public static String assertValidName(String name) {
if (name != null && !name.isEmpty() && name.matches("[_A-Za-z][_0-9A-Za-z]*")) {
if (name != null && !name.isEmpty() && validNamePattern.matcher(name).matches()) {
return name;
}
throw new AssertException(String.format(invalidNameErrorMessage, name));
Expand Down