Skip to content

Commit

Permalink
[321775] Allow parsing Dot Html-Like-Label comments in Html tags.
Browse files Browse the repository at this point in the history
- Modify the DotHtmlLabel grammar to send the HTML_COMMENT elements
nested in a HtmlTag to the hidden channel.
- Implement corresponding DotHtmlLabelTests parser/validation test
cases.
  • Loading branch information
miklossy committed Aug 5, 2017
1 parent f77304e commit 38e5955
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ public void test_comment_with_close_tag() throws Throwable {
parse(DotTestHtmlLabels.COMMENT_WITH_CLOSE_TAG);
}

@Test
public void test_comment_within_table_tag() throws Throwable {
parse(DotTestHtmlLabels.COMMENT_WITHIN_TABLE_TAG);
}

@Test
public void test_comment_within_text() throws Throwable {
parse(DotTestHtmlLabels.COMMENT_WITHIN_TEXT);
}

@Test(timeout = 2000)
public void test_tag_with_attribute() {
parse(DotTestHtmlLabels.TAG_WITH_ATTRIBUTE);
Expand Down Expand Up @@ -140,6 +150,17 @@ public void test_self_closing_tags() {
************************************************************************************************************
*/

@Test
public void test_invalid_comment() throws Throwable {
// HTML comments are not allowed inside a tag
String text = "<B <!--HTML comment--> >string</B>";

HtmlLabel htmlLabel = parseHelper.parse(text);

// verify that there are some reported issues
Assert.assertEquals(8, validationTestHelper.validate(htmlLabel).size());
}

@Test
public void test_tag_wrongly_closed() throws Exception {
String text = "<test>string</B>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@ class DotTestHtmlLabels {
<!-- <tags> -->
<B>Bold Label</B>
'''

public static val COMMENT_WITHIN_TABLE_TAG = '''
<TABLE>
<!-- HTML comment-->
<TR>
<TD>left</TD>
</TR>
</TABLE>
'''

public static val COMMENT_WITHIN_TEXT= '''
<TABLE>
<TR>
<TD>
left <!-- HTML comment 1 -->
<!-- HTML comment 2 -->
right <!-- HTML comment 3 -->
</TD>
</TR>
</TABLE>
'''

public static val FONT_TAG_CONTAINS_TABLE_TAG = '''
<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ HtmlContent: tag=HtmlTag | text=TEXT;
* FIXME: 'HtmlTag' should not support the 'closeName' feature. The closeName is only needed for
* validation to check if the tag is opened and closed with the same name.
*/
HtmlTag hidden(WS): TAG_START name=ID (attributes+=HtmlAttr)*
HtmlTag hidden(WS, HTML_COMMENT): TAG_START name=ID (attributes+=HtmlAttr)*
( selfClosing?=TAG_END_CLOSE
| TAG_END (children+=HtmlContent)* TAG_START_CLOSE closeName=ID TAG_END
);
Expand Down

0 comments on commit 38e5955

Please sign in to comment.