You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Larry Isaacs <La...@sas.com> on 2000/05/25 22:46:15 UTC

[PATCH] Fix for nested <% include ... %> bug

Hi,

The following patch is a quick fix for the nested <% include... %> bug.  This patch has been working for a while with the 3.1 final source.  The following diff is against current Tomcat 3.2 code.

After scanning the Jasper code, I didn't find anywhere that org.apache.jasper.compiler.Mark's "baseDir" field was being used.  For simplicity, the patch uses this field for saving and restoring JspReader's "master" field, rather than adding another field to the Mark class.

======== patchfile.txt ========
--- JspReader.java.orig	Wed May 24 17:25:16 2000
+++ JspReader.java	Thu May 25 15:05:14 2000
@@ -1,4 +1,4 @@
-/*
+ /*
  * The Apache Software License, Version 1.1
  *
  * Copyright (c) 1999 The Apache Software Foundation.  All rights 
@@ -138,13 +138,13 @@
             null : master.substring(0, master.lastIndexOf("/") + 1);
         boolean isAbsolute = name.startsWith("/");
 
-        if (parent == null || isAbsolute)
-            pushFile(new File(name), encoding);
-        else
-            pushFile(new File(parent + name), encoding);
-
-        if (master == null)
+        if (parent == null || isAbsolute) {
             master = name;
+            pushFile(new File(name), encoding);
+        } else {
+            master = parent + name;
+            pushFile(new File(master), encoding);
+        }
     }
 
     /**
@@ -202,10 +202,10 @@
 	    caw.close();
 	    if (current == null) {
 		current = new Mark( this, caw.toCharArray(), fileid, getFile(fileid),
-				    file.getParent(), encoding );
+				    master, encoding );
 	    } else {
 		current.pushStream( caw.toCharArray(), fileid, getFile(fileid),
-				    file.getParent(), encoding );
+				    master, encoding );
 	    }
 
         } catch (FileNotFoundException fnfe) {
@@ -239,7 +239,10 @@
 		(Constants.getString("jsp.error.file.not.registered",
 				     new Object[] {fName}));
 
-	return current.popStream();
+	boolean r = current.popStream();
+	if (r)
+		master = current.baseDir;
+	return r;
     }
 	
     protected JspReader(String file, JspCompilationContext ctx, String encoding) 
===============================

When I run watchdog against the current build, I get a few failures.  The patch above doesn't add any new ones.  For testing, you can add the following files to the webapps/test directory.

======== IncTest.jsp ========
<html><body><ol>
<%@ include file="incr.jsp" %>
<%@ include file="inc/incs.jsp" %>
<%@ include file="inc/nests.jsp" %>
<%@ include file="incr.jsp" %>
<%@ include file="inc/incs.jsp" %>
</ol></body></html>
=============================

========= incr.jsp ==========
<li>incr.jsp
=============================

========= nestr.jsp =========
<li>nestr.jsp<ol>
<%@ include file="incr.jsp" %>
<%@ include file="inc/incs.jsp" %>
<%@ include file="/incr.jsp" %></ol>
=============================

======= inc/incs.jsp ========
<li>incs.jsp
=============================

======= inc/nests.jsp ========
<li>nests.jsp<ol>
<%@ include file="incs.jsp" %>
<%@ include file="/incr.jsp" %>
<%@ include file="incs.jsp" %>
<%@ include file="../incr.jsp" %>
<%@ include file="/inc/incs.jsp" %>
<%@ include file="../nestr.jsp" %>
<%@ include file="incs.jsp" %></ol>
=============================

Then http://localhost:8080/test/IncTest.jsp will correctly generate:

=============================
<html><body><ol>
<li>incr.jsp
<li>incs.jsp
<li>nests.jsp<ol>
<li>incs.jsp
<li>incr.jsp
<li>incs.jsp
<li>incr.jsp
<li>incs.jsp
<li>nestr.jsp<ol>
<li>incr.jsp
<li>incs.jsp
<li>incr.jsp</ol>
<li>incs.jsp</ol>
<li>incr.jsp
<li>incs.jsp
</ol></body></html>
=============================

Larry
__________
Larry Isaacs		
Larry.Isaacs@sas.com
SAS Institute Inc.


Re: [PATCH] Fix for nested <% include ... %> bug

Posted by MANDAR RAJE <ma...@pathfinder.eng.sun.com>.
I thought I already fixed this. Will check on this once
again.

Mandar.

Larry Isaacs wrote:
> 
> Hi,
> 
> The following patch is a quick fix for the nested <% include... %> bug.  This patch has been working for a while with the 3.1 final source.  The following diff is against current Tomcat 3.2 code.
> 
> After scanning the Jasper code, I didn't find anywhere that org.apache.jasper.compiler.Mark's "baseDir" field was being used.  For simplicity, the patch uses this field for saving and restoring JspReader's "master" field, rather than adding another field to the Mark class.
> 
> ======== patchfile.txt ========
> --- JspReader.java.orig Wed May 24 17:25:16 2000
> +++ JspReader.java      Thu May 25 15:05:14 2000
> @@ -1,4 +1,4 @@
> -/*
> + /*
>   * The Apache Software License, Version 1.1
>   *
>   * Copyright (c) 1999 The Apache Software Foundation.  All rights
> @@ -138,13 +138,13 @@
>              null : master.substring(0, master.lastIndexOf("/") + 1);
>          boolean isAbsolute = name.startsWith("/");
> 
> -        if (parent == null || isAbsolute)
> -            pushFile(new File(name), encoding);
> -        else
> -            pushFile(new File(parent + name), encoding);
> -
> -        if (master == null)
> +        if (parent == null || isAbsolute) {
>              master = name;
> +            pushFile(new File(name), encoding);
> +        } else {
> +            master = parent + name;
> +            pushFile(new File(master), encoding);
> +        }
>      }
> 
>      /**
> @@ -202,10 +202,10 @@
>             caw.close();
>             if (current == null) {
>                 current = new Mark( this, caw.toCharArray(), fileid, getFile(fileid),
> -                                   file.getParent(), encoding );
> +                                   master, encoding );
>             } else {
>                 current.pushStream( caw.toCharArray(), fileid, getFile(fileid),
> -                                   file.getParent(), encoding );
> +                                   master, encoding );
>             }
> 
>          } catch (FileNotFoundException fnfe) {
> @@ -239,7 +239,10 @@
>                 (Constants.getString("jsp.error.file.not.registered",
>                                      new Object[] {fName}));
> 
> -       return current.popStream();
> +       boolean r = current.popStream();
> +       if (r)
> +               master = current.baseDir;
> +       return r;
>      }
> 
>      protected JspReader(String file, JspCompilationContext ctx, String encoding)
> ===============================
> 
> When I run watchdog against the current build, I get a few failures.  The patch above doesn't add any new ones.  For testing, you can add the following files to the webapps/test directory.
> 
> ======== IncTest.jsp ========
> <html><body><ol>
> <%@ include file="incr.jsp" %>
> <%@ include file="inc/incs.jsp" %>
> <%@ include file="inc/nests.jsp" %>
> <%@ include file="incr.jsp" %>
> <%@ include file="inc/incs.jsp" %>
> </ol></body></html>
> =============================
> 
> ========= incr.jsp ==========
> <li>incr.jsp
> =============================
> 
> ========= nestr.jsp =========
> <li>nestr.jsp<ol>
> <%@ include file="incr.jsp" %>
> <%@ include file="inc/incs.jsp" %>
> <%@ include file="/incr.jsp" %></ol>
> =============================
> 
> ======= inc/incs.jsp ========
> <li>incs.jsp
> =============================
> 
> ======= inc/nests.jsp ========
> <li>nests.jsp<ol>
> <%@ include file="incs.jsp" %>
> <%@ include file="/incr.jsp" %>
> <%@ include file="incs.jsp" %>
> <%@ include file="../incr.jsp" %>
> <%@ include file="/inc/incs.jsp" %>
> <%@ include file="../nestr.jsp" %>
> <%@ include file="incs.jsp" %></ol>
> =============================
> 
> Then http://localhost:8080/test/IncTest.jsp will correctly generate:
> 
> =============================
> <html><body><ol>
> <li>incr.jsp
> <li>incs.jsp
> <li>nests.jsp<ol>
> <li>incs.jsp
> <li>incr.jsp
> <li>incs.jsp
> <li>incr.jsp
> <li>incs.jsp
> <li>nestr.jsp<ol>
> <li>incr.jsp
> <li>incs.jsp
> <li>incr.jsp</ol>
> <li>incs.jsp</ol>
> <li>incr.jsp
> <li>incs.jsp
> </ol></body></html>
> =============================
> 
> Larry
> __________
> Larry Isaacs
> Larry.Isaacs@sas.com
> SAS Institute Inc.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org