-
Notifications
You must be signed in to change notification settings - Fork 160
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: properly remove block comments from templates #10701
Conversation
@Test | ||
public void removeComments_commentsWithAsterisksInside_commentIsRemoved() { | ||
String result = StringUtil.removeComments( | ||
// @formatter:off | ||
"import { html, LitElement } from 'lit-element';\n" | ||
+ "\n" | ||
+ "export class HelloLit extends LitElement {\n" | ||
+ " /* ******************************************************\n" | ||
+ " * comment\n" | ||
+ " * ******************************************************/\n" | ||
+ "\n" | ||
+ " render() {\n" | ||
+ " return html` <div>Some content</div>`;\n" | ||
+ " }\n" | ||
+ "}\n" | ||
+ "\n" | ||
+ "customElements.define('hello-lit', HelloLit);"); | ||
// @formatter:on | ||
MatcherAssert.assertThat(result, CoreMatchers.allOf( | ||
CoreMatchers.containsString("<div>Some content</div>"), | ||
CoreMatchers.containsString( | ||
"customElements.define('hello-lit', HelloLit);"), | ||
CoreMatchers.not(CoreMatchers.containsString("comment")))); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though this exhibits the error it's not clear why this would fail when the other block tests do not.
The actual problem comes when there is a n%2 amount of asterisks before the / as the check eats up one character after each asterisk.
Also the test didn't show in the failing assertion that the actual problem is that after the block comment there is no string left.
A clearer test would be:
@Test
public void endCommentCheck_shouldNotEatCharacters(){
String blockComment = StringUtil
.removeComments("return html'/* comment **/';");
Assert.assertEquals("return html'';", blockComment);
}
Which on failure will give a clearer exception where one can see that the whole end of the string is missing.
org.junit.ComparisonFailure:
Expected :return html'Code';
Actual :return html'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed with this.
Hi @denis-anisimov , this commit cannot be picked to 6.0 by this bot, can you take a look and pick it manually? |
Hi @denis-anisimov , this commit cannot be picked to 2.6 by this bot, can you take a look and pick it manually? |
Hi @denis-anisimov , this commit cannot be picked to 2.5 by this bot, can you take a look and pick it manually? |
* fix: properly remove block comments from templates fixes #10673
* fix: properly remove block comments from templates fixes #10673
* fix: properly remove block comments from templates fixes #10673
fixes #10673