diff --git a/flow-server/src/main/java/com/vaadin/flow/dom/ElementUtil.java b/flow-server/src/main/java/com/vaadin/flow/dom/ElementUtil.java index 66ab9edcba9..8a45f14b548 100644 --- a/flow-server/src/main/java/com/vaadin/flow/dom/ElementUtil.java +++ b/flow-server/src/main/java/com/vaadin/flow/dom/ElementUtil.java @@ -41,7 +41,8 @@ public class ElementUtil { * https://www.w3.org/TR/html-markup/syntax.html#tag-name "HTML elements all * have names that only use characters in the range 0–9, a–z, and A–Z." */ - private static Pattern tagNamePattern = Pattern.compile("^[a-zA-Z0-9-]+$"); + private static Pattern tagNamePattern = Pattern + .compile("^[a-zA-Z][a-zA-Z0-9-_\\.]*$"); private ElementUtil() { // Util methods only diff --git a/flow-server/src/test/java/com/vaadin/flow/dom/ElementUtilTest.java b/flow-server/src/test/java/com/vaadin/flow/dom/ElementUtilTest.java index c15add420ef..f929fe30fcb 100644 --- a/flow-server/src/test/java/com/vaadin/flow/dom/ElementUtilTest.java +++ b/flow-server/src/test/java/com/vaadin/flow/dom/ElementUtilTest.java @@ -123,4 +123,25 @@ public void toAndFromJsoup() { EXPECTED_TEXT_2, recreatedElement.getChild(0).getChild(1).getText()); } + + @Test + public void isValidTagName_validTagNames() { + Assert.assertTrue(ElementUtil.isValidTagName("foo")); + Assert.assertTrue(ElementUtil.isValidTagName("foo-bar")); + Assert.assertTrue(ElementUtil.isValidTagName("foo_bar")); + Assert.assertTrue(ElementUtil.isValidTagName("foo_bar-baz")); + Assert.assertTrue(ElementUtil.isValidTagName("foo12.bar3")); + Assert.assertTrue(ElementUtil.isValidTagName("foo-._")); + Assert.assertTrue(ElementUtil.isValidTagName("x")); + } + + @Test + public void isValidTagName_invalidTagNames() { + Assert.assertFalse(ElementUtil.isValidTagName("1foo")); + Assert.assertFalse(ElementUtil.isValidTagName("-foo")); + Assert.assertFalse(ElementUtil.isValidTagName("_foo")); + Assert.assertFalse(ElementUtil.isValidTagName(".foo")); + Assert.assertFalse(ElementUtil.isValidTagName("foo>")); + Assert.assertFalse(ElementUtil.isValidTagName("foo$bar")); + } }