You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ukari <gi...@git.apache.org> on 2015/12/17 16:13:29 UTC

[GitHub] tomcat pull request: Change response character encoding

GitHub user ukari opened a pull request:

    https://github.com/apache/tomcat/pull/25

    Change response character encoding

    It seems that encoding was forgotten to be changed in function doFilter().
    
    When I set AddDefaultCharsetFilter in web.xml, like the following:
    ===
    <filter>
      <filter-name>addDefaultCharsetFilter</filter-name>
      <filter-class>org.apache.catalina.filters.AddDefaultCharsetFilter</filter-class>
      <init-param>
        <param-name>encoding</param-name>
        <param-value>utf-8</param-value>
      </init-param>
      <async-supported>true</async-supported>
    </filter>
    <filter-mapping>
      <filter-name>addDefaultCharsetFilter</filter-name>
      <url-pattern>/*</url-pattern>
    </filter-mapping>
    ===
    response encoding is still ISO-8859-1

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/ukari/tomcat trunk

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/tomcat/pull/25.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #25
    
----
commit c8ca385ea55233e44a8be051152083d33c061cea
Author: Muromi Ukari <ch...@gmail.com>
Date:   2015-12-17T15:10:29Z

    change response character encoding
    
    It seems that encoding is forgot to be change in function doFilter().
    
    When I set AddDefaultCharsetFilter in web.xml, like the following:
    ===
    <filter>
      <filter-name>addDefaultCharsetFilter</filter-name>
      <filter-class>org.apache.catalina.filters.AddDefaultCharsetFilter</filter-class>
      <init-param>
        <param-name>encoding</param-name>
        <param-value>utf-8</param-value>
      </init-param>
      <async-supported>true</async-supported>
    </filter>
    <filter-mapping>
      <filter-name>addDefaultCharsetFilter</filter-name>
      <url-pattern>/*</url-pattern>
    </filter-mapping>
    ===
    response encoding is still ISO-8859-1

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[GitHub] tomcat pull request: Change response character encoding

Posted by violetagg <gi...@git.apache.org>.
Github user violetagg commented on the pull request:

    https://github.com/apache/tomcat/pull/25#issuecomment-165781265
  
    I meant an example application which we can use to reproduce the issue that you are describing.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[GitHub] tomcat pull request: Change response character encoding

Posted by ukari <gi...@git.apache.org>.
Github user ukari commented on the pull request:

    https://github.com/apache/tomcat/pull/25#issuecomment-165763957
  
    Oh, you are right, sorry I make the mistake.
    But why response's encoding not changed after I set AddDefaultCharsetFilter?(I mean a HttpServletResponse)
    Is the warpper effective?
    
    Thanks



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[GitHub] tomcat pull request: Change response character encoding

Posted by markt-asf <gi...@git.apache.org>.
Github user markt-asf closed the pull request at:

    https://github.com/apache/tomcat/pull/25


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[GitHub] tomcat pull request: Change response character encoding

Posted by wenjiezhang2013 <gi...@git.apache.org>.
Github user wenjiezhang2013 commented on the pull request:

    https://github.com/apache/tomcat/pull/25#issuecomment-166700042
  
    If you read ```The HTTP specification is clear that if no character set is specified for media sub-types of the "text" media type, the ISO-8859-1 character set must be used. However, browsers may attempt to auto-detect the character set. This may be exploited by an attacker to perform an XSS attack. Internet Explorer and other browsers have an option to enable this behavior.``` from http://tomcat.apache.org/tomcat-8.0-doc/config/filter.html#Add_Default_Character_Set_Filter, you will be able to understand the problem


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[GitHub] tomcat pull request: Change response character encoding

Posted by ukari <gi...@git.apache.org>.
Github user ukari commented on the pull request:

    https://github.com/apache/tomcat/pull/25#issuecomment-165782452
  
    I put that example in email, so you can't see it in github.
    https://drive.google.com/file/d/0BxfFe2h4UJX4OEdMZ2dZMTBvYzBvOEl5Ykx4WUxNVWJiRmpj/view?usp=sharing


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[GitHub] tomcat pull request: Change response character encoding

Posted by wenjiezhang2013 <gi...@git.apache.org>.
Github user wenjiezhang2013 commented on the pull request:

    https://github.com/apache/tomcat/pull/25#issuecomment-166470358
  
    @violetagg is right, it clearly says so from the code
    
     ```java
    @Override
            public void setContentType(String ct) {
    
                if (ct != null && ct.startsWith("text/")) {
                    if (ct.indexOf("charset=") < 0) {
                        super.setContentType(ct + ";charset=" + encoding);
                    } else {
                        super.setContentType(ct);
                        encoding = getCharacterEncoding();
                    }
                } else {
                    super.setContentType(ct);
                }
    
            }
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[GitHub] tomcat pull request: Change response character encoding

Posted by ukari <gi...@git.apache.org>.
Github user ukari commented on the pull request:

    https://github.com/apache/tomcat/pull/25#issuecomment-166806452
  
    Thank both of you very much!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[GitHub] tomcat pull request: Change response character encoding

Posted by violetagg <gi...@git.apache.org>.
Github user violetagg commented on the pull request:

    https://github.com/apache/tomcat/pull/25#issuecomment-166293296
  
    Ok,
    
    I understand now ...
    
    You misunderstood the usage of that filter ...
    
    It is specified in the documentation [1]:
    "encoding - Name of the character set which should be set, if no other character set was set explicitly by a Servlet."
    
    So for example if you specify the following `response.setContentType("text/html");` in your servlet `UsersController` then the specified encoding `UTF-8` will be used and not `ISO-8859-1`.
    
    Regards,
    Violeta
    
    [1] http://tomcat.apache.org/tomcat-8.0-doc/config/filter.html#Add_Default_Character_Set_Filter


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[GitHub] tomcat pull request: Change response character encoding

Posted by violetagg <gi...@git.apache.org>.
Github user violetagg commented on the pull request:

    https://github.com/apache/tomcat/pull/25#issuecomment-165765057
  
    Can you provide a sample example that demonstrates the issue?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[GitHub] tomcat pull request: Change response character encoding

Posted by ukari <gi...@git.apache.org>.
Github user ukari commented on the pull request:

    https://github.com/apache/tomcat/pull/25#issuecomment-165767039
  
    Here is the example
    
    2015-12-18 20:12 GMT+08:00 Wenjie Zhang <no...@github.com>:
    
    > Here is the document for this filter,
    > http://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#Add_Default_Character_Set_Filter
    > ,
    > base on the code, this should work, you might want to debug your code to
    > see what's going on there.
    >
    > —
    > Reply to this email directly or view it on GitHub
    > <https://github.com/apache/tomcat/pull/25#issuecomment-165765309>.
    >



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[GitHub] tomcat pull request: Change response character encoding

Posted by violetagg <gi...@git.apache.org>.
Github user violetagg commented on the pull request:

    https://github.com/apache/tomcat/pull/25#issuecomment-165754059
  
    Hello,
    
    The encoding specified by the user is provided to the ResponseWrapper.
    The ResponseWrapper is provided with the method `doFilter` instead of the original Response. Thus after this filter every component will work with this ResponseWrapper with the correct encoding.
    
    Why do you need to set the encoding to the original Response?
    
    Regards,
    Violeta Georgieva


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[GitHub] tomcat pull request: Change response character encoding

Posted by ukari <gi...@git.apache.org>.
Github user ukari commented on the pull request:

    https://github.com/apache/tomcat/pull/25#issuecomment-166529165
  
    I get it, but it won't work for application/json due to this line 
    ```java
      if (ct != null && ct.startsWith("text/")) {
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[GitHub] tomcat pull request: Change response character encoding

Posted by wenjiezhang2013 <gi...@git.apache.org>.
Github user wenjiezhang2013 commented on the pull request:

    https://github.com/apache/tomcat/pull/25#issuecomment-165765309
  
    Here is the document for this filter, http://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#Add_Default_Character_Set_Filter,
    base on the code, this should work, you might want to debug your code to see what's going on there.
    



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org