struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Qunhuan Mei (JIRA)" <j...@apache.org>
Subject [jira] Created: (WW-3119) Stringlength validation problem for utf-8 chars (Struts 2.1.6)
Date Wed, 06 May 2009 16:50:31 GMT
Stringlength validation problem for utf-8 chars (Struts 2.1.6)
--------------------------------------------------------------

                 Key: WW-3119
                 URL: https://issues.apache.org/struts/browse/WW-3119
             Project: Struts 2
          Issue Type: Bug
          Components: Core Interceptors
    Affects Versions: 2.1.6
         Environment: Win XP, Eclipes, Tomcat
            Reporter: Qunhuan Mei
            Priority: Critical


When I try to validate utf-8 chars such as Chinese using Struts 2.1.6, the stringlength validation
appears to have problem. It seems the validation process is not using the number of Chinese
chars before encoding, but rather the number of chars after encoding. The following are the
steps to reproduce the problem:

1.	Create a project by importing struts2-blank-2.1.6.war from ...\struts-2.1.6\apps" 
and make the login.jsp work with Login.java, e.g. print out the username.length() in setUsername(...)
function.
2.	copy the following stringlength validation code into Login-validation.xml:
<field-validator type="stringlength">
        	<param name="maxLength">4</param>
        	<param name="trim">true</param>
        	<message key="fieldNameShouldBeWithinMaxLength"/>        	
</field-validator>
3.	copy the following stringlength error message into package.properties:
fieldNameShouldBeWithinMaxLength=The max number of chars of ${getText(fieldName)} is ${getText(maxLength)}
4.	run the login.jsp and type in either "abcd" and "abcde" into username, we can see that
"abcd" does not incur a validation message whereas "abcde" does.
5.	now typing 2 Chinese chars, say "世界"into the user name, which should not have any problem
since only 2 chars. However the struts reports the chars received are more than 4. As a matter
of fact, the print out statement in setUsername(...) reports the number of chars is 6.


Qunhuan Mei

BTW: is there any way to access the validation code from struts 2.1.7 (this bug may have been
fixed by the 2.1.7 code)? Thanks.


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message