You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Andrei Prygounkov <bl...@infa.ru> on 2001/04/18 12:36:46 UTC

[PATCH] ParserController.java (jasper include bug)

I think I have found a little bug in jasper of TomCat-4.0.
When jsp-file (1) contains include-file (2)
and this include-file (2) contains another include-file (3), then
jasper does not find include-file (3) if all files are stored not in root
directory of current web application.

For example, I have following directories structure:

  - myapp
     |- file.jsp
     |- include.jsp
     |- include-for-include.jsp
     |- <subfolder>
     |      |- subfolder-file.jsp
     |      |- subfolder-include.jsp
     |      |- subfolder-include-for-include.jsp
     |- <WEB-INF>

Jasper can successfully compile "file.jsp" with all includes.
But it could not compile "subfolder-file.jsp" because it tries to
load file "subfolder-include-for-include.jsp" from path
"myapp/subfolder-include-for-include.jsp" against correct
path "myapp/subfolder/subfolder-include-for-include.jsp".

The source file which corresponds to this problem is
"jakarta-tomcat-4.0/src/jasper/src/share/org/apache/jasper/compiler/ParserController.java".

I have added one line to this file and all works fine now, new line is
marked with "NEW LINE" comment:
=============================== DIFF ===================================
RCS file: /home/cvspublic/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/ParserController.java,v
retrieving revision 1.14
diff -w -i -r1.14 ParserController.java
428a429
>             (isAbsolute ? "" : (String)baseDirStack.peek()) + // NEW LINE
=============================== DIFF ===================================

The changed function is "resolveFileName":

======================= ParserController.java, starting at line 422 =======================
    private String resolveFileName(String inFileName) {
        File file = new File(inFileName);
        boolean isAbsolute = file.getPath().startsWith(File.separator);
        String fileName =
            isAbsolute ?
            inFileName : (String)baseDirStack.peek() + inFileName;
        String baseDir =
            (isAbsolute ? "" : (String)baseDirStack.peek()) + // <== NEW LINE
            inFileName.substring(0, file.getPath().lastIndexOf(File.separator) + 1);
        baseDirStack.push(baseDir);
        return fileName;
    }
======================= ParserController.java =======================

(I am using Tomcat-4.0 nightly build from 2001.04.16 under
Windows NT 4 and jdk-1.3)

Thank you for your time.
     
Best Regards,
Andrei Prygounkov,
black@infa.ru  or  ncuxxu@pisem.net