tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 6518] New: - class name generated from jsp filename mangles some valid identifier characters
Date Mon, 18 Feb 2002 07:04:50 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6518>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6518

class name generated from jsp filename mangles some valid identifier characters

           Summary: class name generated from jsp filename mangles some
                    valid identifier characters
           Product: Tomcat 3
           Version: 3.3 Final
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Major
          Priority: Other
         Component: Jasper
        AssignedTo: tomcat-dev@jakarta.apache.org
        ReportedBy: paul.fu@ssmb.com.au


In both org.apache.jasper.compiler.JspCompiler and
org.apache.jasper.compiler.CommandLineCompiler, the method "getBaseClassName"
generates the servlet classname from the name of the jsp file, and mangles the
characters of the filename to ensure a valid classname.

However, the criteria used to determine if a character should be mangled is only
"Character.isLetterOrDigit" (and hence will generate "1test.java" from
"1test.jsp", which is not a valid Java class). This should be expanded to
include valid non alphanumeric characters (notably "_") as demonstrated in the
patches below (note that the mangling code is the same in both classes)
--- src/share/org/apache/jasper/compiler/JspCompiler.java	Fri Feb 15 22:23:21 2002
+++ JspCompiler.java	Mon Feb 18 17:44:48 2002
@@ -260,10 +260,11 @@
 	// Fix for invalid characters. If you think of more add to the list.
 	StringBuffer modifiedClassName = new StringBuffer();
 	for (int i = 0; i < className.length(); i++) {
-
    if (Character.isLetterOrDigit(className.charAt(i)) == true)
-
	modifiedClassName.append(className.substring(i,i+1));
+
    char c = className.charAt(i);
+
    if ((i == 0 && Character.isJavaIdentifierStart(c)) ||
Character.isJavaIdentifierPart(c))
+
	modifiedClassName.append(c);
 	    else
-
	modifiedClassName.append(mangleChar(className.charAt(i)));
+
	modifiedClassName.append(mangleChar(c));
 	}
 	
 	return modifiedClassName.toString();
// end patch

--- src/share/org/apache/jasper/compiler/CommandLineCompiler.java	Fri Feb 15 22:23:33 2002
+++ CommandLineCompiler.java	Mon Feb 18 17:41:33 2002
@@ -234,10 +234,11 @@
 	// Fix for invalid characters. If you think of more add to the list.
 	StringBuffer modifiedClassName = new StringBuffer();
 	for (int i = 0; i < className.length(); i++) {
-
    if (Character.isLetterOrDigit(className.charAt(i)) == true)
-
	modifiedClassName.append(className.substring(i,i+1));
+           char c = className.charAt(i);
+           if ((i == 0 && Character.isJavaIdentifierStart(c)) ||
Character.isJavaIdentifierPart(c))
+
	modifiedClassName.append(c);
 	    else
-
	modifiedClassName.append(mangleChar(className.charAt(i)));
+
	modifiedClassName.append(mangleChar(c));
 	}
 	
 	return modifiedClassName.toString();// end patch

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message