Bug 60769 - Problem with Jsp character encoding configuration
Summary: Problem with Jsp character encoding configuration
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Jasper (show other bugs)
Version: 8.5.11
Hardware: PC All
: P2 normal (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-23 08:16 UTC by Lazar
Modified: 2017-03-01 21:00 UTC (History)
0 users



Attachments
The two sample applications reproducing the problems (1.80 KB, application/x-zip-compressed)
2017-02-23 08:16 UTC, Lazar
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lazar 2017-02-23 08:16:44 UTC
Created attachment 34775 [details]
The two sample applications reproducing the problems

On Tomcat 8.5.11 the attached sample.war, which declares UTF-8 encoding through a configuration element and Windows-1252 with the XML prolog of the test.jspx file, does not throw an exception and displays the jspx content. But it works as expected and throws an exception for the index.jsp, which declares again a different encoding from the one declared through JSP configuration in web.xml. I would expect that both the index.jsp and test.jspx from sample.war should throw an exception, as they do on Tomcat 8.5.5 for example.

Also, if in a jspx file I declare one and the same encoding (in my case Windows-1252) in both the XML prolog and the page directive pageEncoding property, I get the error message:
"Page-encoding specified in XML prolog (UTF-8) is different from that specified in page directive (WINDOWS-1252)", while on Tomcat 8.5.5 I get no error and the page is displayed. This is in sample1.war, enctext.jspx file.

These behaviors are probably due to change

https://github.com/apache/tomcat85/commit/a03c5755a6fa2d9daa43abe357628f475230fdb2 ?

If the two issues are unrelated I will open another bug report for the second one.

Reference to relating sections of JSP 2.3 spec:

section 3.3.4 (Declaring page encodings):
"It is also a translation-time error to name different encodings in the prolog / text declaration of the document in XML syntax and in a JSP configuration element matching the document. It is legal to name the same encoding through multiple mechanisms."


section 4.1.2 (XML Syntax):
"It is a translation-time error to name different encodings in two or more of the following: the XML prolog / text declaration of a JSP document, the pageEncoding attribute of the page directive of the JSP document, and in a JSP configuration element whose URL pattern matches the document."

Regards,
Lazar
Comment 1 Mark Thomas 2017-03-01 21:00:57 UTC
Yes, there was a regression in the refactoring. The detected BOM encoding was incorrectly taking precedence over the prolog specified encoding (if any).

Thanks for the report and the test case.