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: extend and clarify valid tag names #10801

Merged
merged 1 commit into from
Apr 26, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,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"));
}
}