Skip to content

Commit 65a8104

Browse files
committed
fix for npe in regex check for amp carousel
1 parent 1323e4b commit 65a8104

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

‎src/main/java/dev/amp/validator/utils/AttributeSpecUtils.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,11 +598,16 @@ public static void validateAttrDeclaration(
598598
* @param value value.
599599
* @return {boolean}
600600
*/
601-
public static boolean attrValueHasTemplateSyntax(@Nonnull final String value) {
601+
public static boolean attrValueHasTemplateSyntax(final String value) {
602602
// Mustache (https://mustache.github.io/mustache.5.html), our template
603603
// system, supports replacement tags that start with {{ and end with }}.
604604
// We relax attribute value rules if the value contains this syntax as we
605605
// will validate the post-processed tag instead.
606+
607+
if (value == null) {
608+
return false;
609+
}
610+
606611
return MUSTACHE_TAG_PATTERN.matcher(value).matches();
607612
}
608613

‎src/test/java/dev/amp/validator/parser/AMPHtmlParserTest.java‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ public void testAmpSelectorsPass() {
5555
}
5656
}
5757

58+
@Test
59+
public void testCarousel() {
60+
try {
61+
String inputHtml =
62+
readFile(
63+
"test-cases/tags/testAmpCarousel.html");
64+
final int maxNode = 10000;
65+
ValidatorProtos.ValidationResult result =
66+
ampHtmlParser.parse(inputHtml, ValidatorProtos.HtmlFormat.Code.AMP4EMAIL, ExitCondition.FULL_PARSING, maxNode);
67+
Assert.assertEquals(result.getErrorsCount(), 0, "Expecting to have 0 error");
68+
} catch (final IOException ex) {
69+
ex.printStackTrace();
70+
}
71+
}
72+
5873
@Test
5974
public void testAmpList() {
6075
try {

‎src/test/resources/test-cases/tags/testAmpList.html‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<!--
22
AMP-LIST
33
-->
4-
<!--
5-
AMP-LIST
6-
-->
74
<!doctype html>
85
<html ⚡4email>
96
<head>

0 commit comments

Comments
 (0)