Return-Path: Delivered-To: apmail-jakarta-tomcat-dev-archive@apache.org Received: (qmail 37070 invoked from network); 9 Apr 2003 18:16:39 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 9 Apr 2003 18:16:39 -0000 Received: (qmail 4242 invoked by uid 97); 9 Apr 2003 18:18:34 -0000 Delivered-To: qmlist-jakarta-archive-tomcat-dev@nagoya.betaversion.org Received: (qmail 4235 invoked from network); 9 Apr 2003 18:18:34 -0000 Received: from daedalus.apache.org (HELO apache.org) (208.185.179.12) by nagoya.betaversion.org with SMTP; 9 Apr 2003 18:18:34 -0000 Received: (qmail 36203 invoked by uid 500); 9 Apr 2003 18:16:30 -0000 Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Developers List" Reply-To: "Tomcat Developers List" Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 36192 invoked from network); 9 Apr 2003 18:16:29 -0000 Received: from pluto.phpwebhosting.com (64.29.16.28) by daedalus.apache.org with SMTP; 9 Apr 2003 18:16:29 -0000 Received: (qmail 8343 invoked by uid 508); 9 Apr 2003 18:14:14 -0000 Received: from unknown (HELO tripper) (65.100.41.196) by pluto.phpwebhosting.com with SMTP; 9 Apr 2003 18:14:14 -0000 Date: Wed, 9 Apr 2003 11:16:22 -0700 From: Chris Fesler X-Mailer: The Bat! (v1.53d) Reply-To: Chris Fesler X-Priority: 3 (Normal) Message-ID: <11678043841.20030409111622@fesler.org> To: tomcat-dev@jakarta.apache.org Subject: [patch] JspC.java (tomcat_4_branch) toPackageName() bug MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N In the latest tomcat_4_branch version of JspC.java (1.12.2.6), toPackageName(String jspUri) fails to return a valid package declaration if one of the path elements (i.e., directory names) begins with a character that is a valid identifier part, but not a valid identifier start. An example: toPackageName("hope0/1.0.0/welcome") * JspC.java 1.12.2.6 returns: package hope0.1_0002e0_0002e0.welcome This fails to compile because a Java identifier may not begin with a numeral (Java Language Spec, section 3.8), as the second identifier (1_0002e0_0002e0) does. * JspC.java 1.12.2.6 with included patch returns: package hope0._1_0002e0_0002e0.welcome Which works just fine. The patch also makes the indentation of the toPackageName() more consistent; I used 4 spaces (not tabs) for each indent. Chris Fesler cf-lists@fesler.org patch follows ------------- Index: JspC.java =================================================================== RCS file: /home/cvspublic/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspC.java,v retrieving revision 1.12.2.6 diff -u -r1.12.2.6 JspC.java --- JspC.java 17 Mar 2003 20:53:39 -0000 1.12.2.6 +++ JspC.java 9 Apr 2003 17:50:06 -0000 @@ -996,23 +996,29 @@ private String toPackageName(String jspUri) { StringBuffer modifiedPackageName = new StringBuffer(); int iSep = jspUri.lastIndexOf('/'); - // Start after the first slash + // Start after the first slash int nameStart = 1; - for (int i = 1; i < iSep; i++) { - char ch = jspUri.charAt(i); - if (Character.isJavaIdentifierPart(ch)) { - modifiedPackageName.append(ch); - } - else if (ch == '/') { + for (int i = 1; i < iSep; i++) { + char ch = jspUri.charAt(i); + + if (i == nameStart) { + if (! Character.isJavaIdentifierStart(ch)) { + modifiedPackageName.append('_'); + } + } + + if (Character.isJavaIdentifierPart(ch)) { + modifiedPackageName.append(ch); + } else if (ch == '/') { if (isJavaKeyword(jspUri.substring(nameStart, i))) { modifiedPackageName.append('_'); } nameStart = i+1; - modifiedPackageName.append('.'); - } else { - modifiedPackageName.append(mangleChar(ch)); - } - } + modifiedPackageName.append('.'); + } else { + modifiedPackageName.append(mangleChar(ch)); + } + } if (nameStart < iSep && isJavaKeyword(jspUri.substring(nameStart, iSep))) { modifiedPackageName.append('_'); } --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org