Backport of PR #1617 (#1658)
* [NETBEANS-3335] Enhance robustness of HTML Lexer
After the update of the HTML lexer to support HTML5 style attributes,
new states in the lexer can be reached. Instead of bailing out with a
NullPointerException in HtmlLexer#equals, report comparisons with NULL
as false.
* [NETBEANS-3335] Enhance robustness of HTML Lexer
Add unittest to prevent regression
* Increment specification version for html.lexer
diff --git a/ide/html.lexer/manifest.mf b/ide/html.lexer/manifest.mf
index d2b7858..7490d56 100644
--- a/ide/html.lexer/manifest.mf
+++ b/ide/html.lexer/manifest.mf
@@ -1,5 +1,5 @@
OpenIDE-Module: org.netbeans.modules.html.lexer/1
OpenIDE-Module-Localizing-Bundle: org/netbeans/lib/html/lexer/Bundle.properties
-OpenIDE-Module-Specification-Version: 1.44
+OpenIDE-Module-Specification-Version: 1.44.1
OpenIDE-Module-Layer: org/netbeans/lib/html/lexer/layer.xml
AutoUpdate-Show-In-Client: false
diff --git a/ide/html.lexer/src/org/netbeans/lib/html/lexer/HtmlLexer.java b/ide/html.lexer/src/org/netbeans/lib/html/lexer/HtmlLexer.java
index b908ff9..d44dafd 100644
--- a/ide/html.lexer/src/org/netbeans/lib/html/lexer/HtmlLexer.java
+++ b/ide/html.lexer/src/org/netbeans/lib/html/lexer/HtmlLexer.java
@@ -1552,8 +1552,12 @@
/** @param optimized - first sequence is lowercase, one call to Character.toLowerCase() */
private static boolean equals(CharSequence text1, CharSequence text2, boolean ignoreCase, boolean optimized) {
- assert text1 != null : "text1 arg is null";
- assert text2 != null : "text2 arg is null";
+ if (text1 == text2) {
+ return true;
+ }
+ if (text1 == null || text2 == null) {
+ return false;
+ }
if (text1.length() != text2.length()) {
return false;
} else {
diff --git a/php/php.smarty/test/unit/data/testfiles/parserErrors/testParserNETBEANS3335_01.tpl b/php/php.smarty/test/unit/data/testfiles/parserErrors/testParserNETBEANS3335_01.tpl
new file mode 100644
index 0000000..c476b59
--- /dev/null
+++ b/php/php.smarty/test/unit/data/testfiles/parserErrors/testParserNETBEANS3335_01.tpl
@@ -0,0 +1 @@
+<a {if $smarty.server.REQUEST_URI|strstr:"/new"}class="underline"{/if} href="{url('new')}">
diff --git a/php/php.smarty/test/unit/data/testfiles/parserErrors/testParserNETBEANS3335_01.tpl.errors b/php/php.smarty/test/unit/data/testfiles/parserErrors/testParserNETBEANS3335_01.tpl.errors
new file mode 100644
index 0000000..607da0e
--- /dev/null
+++ b/php/php.smarty/test/unit/data/testfiles/parserErrors/testParserNETBEANS3335_01.tpl.errors
@@ -0,0 +1 @@
+Detected parser errors in the file:
diff --git a/php/php.smarty/test/unit/data/testfiles/parserErrors/testParserNETBEANS3335_02.tpl b/php/php.smarty/test/unit/data/testfiles/parserErrors/testParserNETBEANS3335_02.tpl
new file mode 100644
index 0000000..f6bb7c3
--- /dev/null
+++ b/php/php.smarty/test/unit/data/testfiles/parserErrors/testParserNETBEANS3335_02.tpl
@@ -0,0 +1 @@
+<div class="{if $test eq ""}toto{/if}" {if $test}id="titi"{/if}></div>
diff --git a/php/php.smarty/test/unit/data/testfiles/parserErrors/testParserNETBEANS3335_02.tpl.errors b/php/php.smarty/test/unit/data/testfiles/parserErrors/testParserNETBEANS3335_02.tpl.errors
new file mode 100644
index 0000000..607da0e
--- /dev/null
+++ b/php/php.smarty/test/unit/data/testfiles/parserErrors/testParserNETBEANS3335_02.tpl.errors
@@ -0,0 +1 @@
+Detected parser errors in the file:
diff --git a/php/php.smarty/test/unit/src/org/netbeans/modules/php/smarty/editor/parser/TplParserErrorsTest.java b/php/php.smarty/test/unit/src/org/netbeans/modules/php/smarty/editor/parser/TplParserErrorsTest.java
index 1ef5f93..1caa6f3 100644
--- a/php/php.smarty/test/unit/src/org/netbeans/modules/php/smarty/editor/parser/TplParserErrorsTest.java
+++ b/php/php.smarty/test/unit/src/org/netbeans/modules/php/smarty/editor/parser/TplParserErrorsTest.java
@@ -118,6 +118,15 @@
assertParserErrors();
}
+ // no errors
+ public void testParserNETBEANS3335_01() throws Exception {
+ assertParserErrors();
+ }
+
+ public void testParserNETBEANS3335_02() throws Exception {
+ assertParserErrors();
+ }
+
private String getTestFileRelPath() {
return "testfiles/parserErrors/" + getName() + ".tpl";
}