You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2010/07/06 18:47:39 UTC
svn commit: r960942 - in /tomcat/trunk:
java/org/apache/el/parser/AstDotSuffix.java
java/org/apache/el/parser/AstIdentifier.java
java/org/apache/el/util/Validation.java webapps/docs/changelog.xml
Author: markt
Date: Tue Jul 6 16:47:39 2010
New Revision: 960942
URL: http://svn.apache.org/viewvc?rev=960942&view=rev
Log:
Improve fix for https://issues.apache.org/bugzilla/show_bug.cgi?id=49217
Make sure identifiers meet the requirements of the JLS
Modified:
tomcat/trunk/java/org/apache/el/parser/AstDotSuffix.java
tomcat/trunk/java/org/apache/el/parser/AstIdentifier.java
tomcat/trunk/java/org/apache/el/util/Validation.java
tomcat/trunk/webapps/docs/changelog.xml
Modified: tomcat/trunk/java/org/apache/el/parser/AstDotSuffix.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/parser/AstDotSuffix.java?rev=960942&r1=960941&r2=960942&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/parser/AstDotSuffix.java (original)
+++ tomcat/trunk/java/org/apache/el/parser/AstDotSuffix.java Tue Jul 6 16:47:39 2010
@@ -41,7 +41,7 @@ public final class AstDotSuffix extends
@Override
public void setImage(String image) {
- if (Validation.isJavaKeyword(image)) {
+ if (!Validation.isIdentifier(image)) {
throw new ELException("Can't use Java keyword as identifier");
}
this.image = image;
Modified: tomcat/trunk/java/org/apache/el/parser/AstIdentifier.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/parser/AstIdentifier.java?rev=960942&r1=960941&r2=960942&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/parser/AstIdentifier.java (original)
+++ tomcat/trunk/java/org/apache/el/parser/AstIdentifier.java Tue Jul 6 16:47:39 2010
@@ -128,7 +128,7 @@ public final class AstIdentifier extends
@Override
public void setImage(String image) {
- if (Validation.isJavaKeyword(image)) {
+ if (!Validation.isIdentifier(image)) {
throw new ELException("Can't use Java keyword as identifier");
}
this.image = image;
Modified: tomcat/trunk/java/org/apache/el/util/Validation.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/util/Validation.java?rev=960942&r1=960941&r2=960942&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/util/Validation.java (original)
+++ tomcat/trunk/java/org/apache/el/util/Validation.java Tue Jul 6 16:47:39 2010
@@ -19,15 +19,16 @@ package org.apache.el.util;
public class Validation {
- private static final String javaKeywords[] = { "abstract", "assert",
- "boolean", "break", "byte", "case", "catch", "char", "class",
- "const", "continue", "default", "do", "double", "else", "enum",
- "extends", "final", "finally", "float", "for", "goto", "if",
- "implements", "import", "instanceof", "int", "interface", "long",
- "native", "new", "package", "private", "protected", "public",
- "return", "short", "static", "strictfp", "super", "switch",
- "synchronized", "this", "throw", "throws", "transient", "try",
- "void", "volatile", "while" };
+ // Java keywords, boolean literals & the null literal in alphabetical order
+ private static final String invalidIdentifiers[] = { "abstract", "assert",
+ "boolean", "break", "byte", "case", "catch", "char", "class", "const",
+ "continue", "default", "do", "double", "else", "enum", "extends",
+ "false", "final", "finally", "float", "for", "goto", "if", "implements",
+ "import", "instanceof", "int", "interface", "long", "native", "new",
+ "null", "package", "private", "protected", "public", "return", "short",
+ "static", "strictfp", "super", "switch", "synchronized", "this",
+ "throw", "throws", "transient", "true", "try", "void", "volatile",
+ "while" };
private Validation() {
@@ -35,16 +36,23 @@ public class Validation {
}
/**
- * Test whether the argument is a Java keyword
+ * Test whether the argument is a Java identifier.
*/
- public static boolean isJavaKeyword(String key) {
+ public static boolean isIdentifier(String key) {
+
+ // Should not be the case but check to be sure
+ if (key == null || key.length() == 0) {
+ return false;
+ }
+
+ // Check the list of known invalid values
int i = 0;
- int j = javaKeywords.length;
+ int j = invalidIdentifiers.length;
while (i < j) {
int k = (i + j) / 2;
- int result = javaKeywords[k].compareTo(key);
+ int result = invalidIdentifiers[k].compareTo(key);
if (result == 0) {
- return true;
+ return false;
}
if (result < 0) {
i = k + 1;
@@ -52,6 +60,19 @@ public class Validation {
j = k;
}
}
- return false;
+
+ // Check the start character that has more restrictions
+ if (!Character.isJavaIdentifierStart(key.charAt(0))) {
+ return false;
+ }
+
+ // Check each remaining character used is permitted
+ for (int idx = 1; idx < key.length(); idx++) {
+ if (!Character.isJavaIdentifierPart(key.charAt(idx))) {
+ return false;
+ }
+ }
+
+ return true;
}
}
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=960942&r1=960941&r2=960942&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Tue Jul 6 16:47:39 2010
@@ -128,7 +128,8 @@
MethodExpressions is used in EL. (markt)
</fix>
<fix>
- <bug>49217</bug>: Prevent use of Java keywords in identifiers. (markt)
+ <bug>49217</bug>: Ensure that identifiers used in EL meet the
+ requirements of the Java Language Specification. (markt)
</fix>
</changelog>
</subsection>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org