Author: markt
Date: Mon Jul 5 21:45:26 2010
New Revision: 960712
URL: http://svn.apache.org/viewvc?rev=960712&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49217
Prevent use of Java keywords in identifiers
Added:
tomcat/trunk/java/org/apache/el/util/Validation.java (with props)
Modified:
tomcat/trunk/java/org/apache/el/parser/AstDotSuffix.java
tomcat/trunk/java/org/apache/el/parser/AstIdentifier.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=960712&r1=960711&r2=960712&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/parser/AstDotSuffix.java (original)
+++ tomcat/trunk/java/org/apache/el/parser/AstDotSuffix.java Mon Jul 5
21:45:26 2010
@@ -21,6 +21,7 @@ package org.apache.el.parser;
import javax.el.ELException;
import org.apache.el.lang.EvaluationContext;
+import org.apache.el.util.Validation;
/**
@@ -37,4 +38,12 @@ public final class AstDotSuffix extends
throws ELException {
return this.image;
}
+
+ @Override
+ public void setImage(String image) {
+ if (Validation.isJavaKeyword(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=960712&r1=960711&r2=960712&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/parser/AstIdentifier.java (original)
+++ tomcat/trunk/java/org/apache/el/parser/AstIdentifier.java Mon Jul 5
21:45:26 2010
@@ -28,6 +28,7 @@ import javax.el.VariableMapper;
import org.apache.el.lang.EvaluationContext;
import org.apache.el.util.MessageFactory;
+import org.apache.el.util.Validation;
/**
@@ -125,6 +126,14 @@ public final class AstIdentifier extends
return this.getMethodExpression(ctx).getMethodInfo(ctx.getELContext());
}
+ @Override
+ public void setImage(String image) {
+ if (Validation.isJavaKeyword(image)) {
+ throw new ELException("Can't use Java keyword as identifier");
+ }
+ this.image = image;
+ }
+
private final MethodExpression getMethodExpression(EvaluationContext ctx)
throws ELException {
Object obj = null;
Added: 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=960712&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/el/util/Validation.java (added)
+++ tomcat/trunk/java/org/apache/el/util/Validation.java Mon Jul 5 21:45:26
2010
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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" };
+
+
+ private Validation() {
+ // Utility class. Hide default constructor
+ }
+
+ /**
+ * Test whether the argument is a Java keyword
+ */
+ public static boolean isJavaKeyword(String key) {
+ int i = 0;
+ int j = javaKeywords.length;
+ while (i < j) {
+ int k = (i + j) / 2;
+ int result = javaKeywords[k].compareTo(key);
+ if (result == 0) {
+ return true;
+ }
+ if (result < 0) {
+ i = k + 1;
+ } else {
+ j = k;
+ }
+ }
+ return false;
+ }
+}
Propchange: tomcat/trunk/java/org/apache/el/util/Validation.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=960712&r1=960711&r2=960712&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Mon Jul 5 21:45:26 2010
@@ -127,6 +127,9 @@
Correct algorithm used to identify correct method to use when a
MethodExpressions is used in EL. (markt)
</fix>
+ <fix>
+ <bug>49217</bug>: Prevent use of Java keywords in identifiers. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Cluster">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]