Skip to content

Commit

Permalink
fix: extend and clarify valid tag names (#10801) (#10803)
Browse files Browse the repository at this point in the history
fixes #9669

Co-authored-by: Denis <denis@vaadin.com>
  • Loading branch information
vaadin-bot and Denis committed Apr 26, 2021
1 parent 06f7417 commit 45bdb88
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions flow-server/src/test/java/com/vaadin/flow/dom/ElementUtilTest.java
Expand Up @@ -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"));
}
}

0 comments on commit 45bdb88

Please sign in to comment.