Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Correct regexp to only match when digit first #9496

Merged
merged 1 commit into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @since 1.0
*/
public final class CustomElementNameValidator {
private static final Pattern STARTS_WITH_A_DIGIT = Pattern.compile("\\d.*");
private static final Pattern STARTS_WITH_A_DIGIT = Pattern.compile("^\\d.*");

private static final Set<String> RESERVED_NAMES = Stream
.of("annotation-xml", "color-profile", "font-face", "font-face-src",
Expand Down Expand Up @@ -58,7 +58,7 @@ public static boolean isCustomElementName(String name) {
private static boolean checkHtmlTagRules(String name) {
return !name.isEmpty() && name.equals(name.toLowerCase(Locale.ENGLISH))
&& !name.startsWith("-")
&& !STARTS_WITH_A_DIGIT.matcher(name).matches();
&& !STARTS_WITH_A_DIGIT.matcher(name).find();
}

private static boolean checkWebComponentRules(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public class CustomElementNameValidatorTest {
@Test
public void testInvalidElementNames() {
Stream.of("", "foo", "annotation-xml", "0-foo", "-foo", "foo-$",
"foo-/", "FOO-BAR", "foo/", "øl-unicorn", "foo-💩")
"foo-/", "FOO-BAR", "foo/", "øl-unicorn", "foo-💩", "5th-element")
.forEach(name -> Assert.assertFalse(String.format(
"Name %s is valid even though it should not be", name),
CustomElementNameValidator.isCustomElementName(name)));
}

@Test
public void testValidNamesWithoutErrorOrWarning() {
Stream.of("foo-bar", "custom-element", "date-field", "dos-box")
Stream.of("foo-bar", "custom-element", "date-field", "dos-box", "home-4-good")
.forEach(name -> Assert.assertTrue(String.format(
"Name %s is not valid even though it should be", name),
CustomElementNameValidator.isCustomElementName(name)));
Expand Down