Bug 25899 - Encoding bug in Jasper compiler when using <%@ include > directive (pageEncoding attribute)
Summary: Encoding bug in Jasper compiler when using <%@ include > directive (pageEncod...
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 4
Classification: Unclassified
Component: Jasper 2 (show other bugs)
Version: 4.1.31
Hardware: All other
: P3 normal with 3 votes (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
: 29386 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-01-05 12:55 UTC by Rafal Maczewski
Modified: 2004-11-28 14:16 UTC (History)
3 users (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rafal Maczewski 2004-01-05 12:55:47 UTC
There is a bug in Jasper compiler that incorrectly assigns ISO-8859-1 encoding 
for included file when including files using <%@ include file="..."> directive 
and the included file contains <%@ page > directive.

For example:

page1.jsp:
<%@ page contentType="text/html; charset=ISO-8859-2" %>

Test łćżĆŁŃ
<br><br>

<%@ include file="page2.jsp"%> 

page2.jsp:
<%@ page import="java.util.*" %>

Test łćżĆŁŃ
<br><br>


Jasper correctly recognizes encoding of file page1.jsp as ISO-8859-2. Since 
page2.jsp does not have its encoding set and it is included from page1.jsp, it 
should also have ISO-8859-2 encoding. Jasper incorrectly treats this file as 
having ISO-8859-1 encoding. 
The problem disappears when <%@ page import="java.util.*" %> directive is 
removed from page2.jsp.

Patch for this bug follows:
Index: ParserController.java
===================================================================
RCS file: /home/cvspublic/jakarta-tomcat-
jasper/jasper2/src/share/org/apache/jasper/compiler/ParserController.java,v
retrieving revision 1.4.2.1
diff -c -r1.4.2.1 ParserController.java
*** ParserController.java	18 Jul 2002 18:04:24 -0000	1.4.2.1
--- ParserController.java	5 Jan 2004 12:52:09 -0000
***************
*** 260,270 ****
  			    int loc = contentType.indexOf("charset=");
  			    if (loc != -1) {
  				newEncoding = contentType.substring(loc+8);
- 				return;
  			    }
  			}
- 			if (newEncoding == null)
- 			    newEncoding = "ISO-8859-1";
  		    } else {
  			return;
  		    }
--- 260,270 ----
  			    int loc = contentType.indexOf("charset=");
  			    if (loc != -1) {
  				newEncoding = contentType.substring(loc+8);
  			    }
+ 			    if (newEncoding == null)
+ 			        newEncoding = "ISO-8859-1";
+ 			    return;
  			}
  		    } else {
  			return;
  		    }
Comment 1 sk 2004-11-18 17:56:50 UTC
Could we have some update on this bug? 
I can confirm this for tomcat 4.1.31 as well

As a workaround, just put the import page directive into a new file and include
this file from the original location.

I'll add "pageEncoding" to the summary to make this more visible.
Comment 2 Mark Thomas 2004-11-28 23:01:14 UTC
This has been fixed in CVS for 4.1.x.

Please note that the suggested patch is bad as it does not take account of JSP 
1.2 errata (rev a) of 21 March 2002 which clarifies a number of issues 
regarding page encoding. An alternative patch has been applied.
Comment 3 Mark Thomas 2004-11-28 23:16:59 UTC
*** Bug 29386 has been marked as a duplicate of this bug. ***