You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Lorenzo Cerulli (JIRA)" <de...@myfaces.apache.org> on 2008/03/23 21:09:25 UTC

[jira] Created: (MYFACES-1841) HtmlResponseWriterImpl.writeURIAttribute does not perform proper URLs encoding ( ex: & should be encoded in &)

HtmlResponseWriterImpl.writeURIAttribute does not perform proper URLs encoding  ( ex: & should be encoded in &amp)
------------------------------------------------------------------------------------------------------------------

                 Key: MYFACES-1841
                 URL: https://issues.apache.org/jira/browse/MYFACES-1841
             Project: MyFaces Core
          Issue Type: Bug
          Components: General, Portlet_Support
    Affects Versions:  1.2.0, 1.1.5, 1.1.4
         Environment: Windows xp sp2->Jboss portal  2.4.2->tomcat 5.5 ->JSF portlet 
            Reporter: Lorenzo Cerulli


HtmlFormRenderer is the class in charge of rendering the UIForm component and all the required attibutes.
This class is in charge of rendering  for example the Form component  tinto <form id="foo" name="bar" action=/HelloWorldJSFPortletWindow?action=1&org.apache.myfaces.portlet.MyFacesGenericPortlet.VIEW_ID=%2FWEB-INF%2Fjsp%2Findex. .....> </form>

During the rendering process the form renderer uses  HtmlResponseWriterImpl.writeURIAttribute to write the "action" attribute of the form component.

Generally speaking the action attribute should be acquired using "context.getApplication().getViewHandler().getActionURL(context, viewid))" and the result  MUST be encoded using "context.getExternalContext().encodeActionURL" before passing the url to the "HtmlResponseWriterImpl.writeURIAttribute(URL);" This way the URL will be well formed and will be correctly encoded in the action attribute.

Even if the HtmlFormRendererBase for example correctly implements this process the resulting URL is encoded in the action attribute without correctly transforming "&" in "&amp". The main reason is probably that internally the HtmlResponseWriterImpl.writeURIAttribute does not call org.apache.myfaces.shared_impl.renderkit.html.util.HTMLEncoder.encode before writing out the attribute.
The HTMLEncoder.encode  infact is called only if the URI starts with the "javascript:" prefix.
This is IMO an error and should be fixed.

This behaviour gives us some problem for exmaple with the W3C validator even with html 4.0 strict






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


[jira] Updated: (MYFACES-1841) HtmlResponseWriterImpl.writeURIAttribute does not perform proper URLs encoding ( ex: & should be encoded in &)

Posted by "Leonardo Uribe (JIRA)" <de...@myfaces.apache.org>.
     [ https://issues.apache.org/jira/browse/MYFACES-1841?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Leonardo Uribe updated MYFACES-1841:
------------------------------------

    Status: Patch Available  (was: Open)

> HtmlResponseWriterImpl.writeURIAttribute does not perform proper URLs encoding  ( ex: & should be encoded in &amp)
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: MYFACES-1841
>                 URL: https://issues.apache.org/jira/browse/MYFACES-1841
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: General, Portlet_Support
>    Affects Versions: 1.1.4, 1.1.5,  1.2.0
>         Environment: Windows xp sp2->Jboss portal  2.4.2->tomcat 5.5 ->JSF portlet 
>            Reporter: Lorenzo Cerulli
>         Attachments: MYFACES-1841-1.patch
>
>
> HtmlFormRenderer is the class in charge of rendering the UIForm component and all the required attibutes.
> This class is in charge of rendering  for example the Form component  tinto <form id="foo" name="bar" action=/HelloWorldJSFPortletWindow?action=1&org.apache.myfaces.portlet.MyFacesGenericPortlet.VIEW_ID=%2FWEB-INF%2Fjsp%2Findex. .....> </form>
> During the rendering process the form renderer uses  HtmlResponseWriterImpl.writeURIAttribute to write the "action" attribute of the form component.
> Generally speaking the action attribute should be acquired using "context.getApplication().getViewHandler().getActionURL(context, viewid))" and the result  MUST be encoded using "context.getExternalContext().encodeActionURL" before passing the url to the "HtmlResponseWriterImpl.writeURIAttribute(URL);" This way the URL will be well formed and will be correctly encoded in the action attribute.
> Even if the HtmlFormRendererBase for example correctly implements this process the resulting URL is encoded in the action attribute without correctly transforming "&" in "&amp". 
> At this point we can argue that this bug could be generated by two different sources:
> 1. Not correct URL encding perfomed by javax.faces.context.FacesContext  during  context.getExternalContext().encodeActionURL[this is non related to myfaces and probably depend on the PortletResponse object implemented by the container JBOSS portal in this case]
> 2. Nor correct URI encoding within HtmlResponseWriterImpl.writeURIAttribute(URL) [related to myfaces]
> Analyzing the source code of the latter i noticed that writeURIAttribute(URL) internally calls the HTMLEncoder.encode method to perform string encoding if the URI starts with the "javascript" prefix otherwise does not perform any kind of encoding.
> Probably this is a bug bacause an enforcment of URI encoding rules should be provided in any case;

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


[jira] Issue Comment Edited: (MYFACES-1841) HtmlResponseWriterImpl.writeURIAttribute does not perform proper URLs encoding ( ex: & should be encoded in &)

Posted by "Lorenzo Cerulli (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-1841?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12581611#action_12581611 ] 

lcerulli edited comment on MYFACES-1841 at 3/24/08 11:32 AM:
--------------------------------------------------------------------

Just to give some additional information the text below comes form the JSF spec 1.2 maintenance release 2006 specification (and it's the same in the 1.1 spec):

"public void writeAttribute(String name, Object value, String
componentPropertyName) throws IOException;

public void writeURIAttribute(String name, Object value, String
componentPropertyName) throws IOException;

These methods add an attribute name/value pair to an element that was opened with a
previous call to startElement(), throwing an exception if there is no currently open
element. The writeAttribute() method causes character encoding to be performed in
the same manner as that performed by the writeText() methods. The
writeURIAttribute() method assumes that the attribute value is a URI, and performs
URI encoding (such as % encoding for HTML)" -> Chapter 6-10 [page 210]

The important part is obviously the last sentence
Below you can find the R.I. implementation:

----------------------------------Reference implementation-------------------------------------------------------
   public void writeURIAttribute(String name, Object value, String componentPropertyName)
        throws IOException
    {
        if(name == null || value == null)
            throw new NullPointerException(Util.getExceptionMessageString("com.sun.faces.NULL_PARAMETERS_ERROR"));
        writer.write(" ");
        writer.write(name);
        writer.write("=\"");
        String stringValue = value.toString();
        if(stringValue.startsWith("javascript:"))
            HtmlUtils.writeAttribute(writer, buffer, stringValue);
        else

            HtmlUtils.writeURL(writer, stringValue, encoding);------->This IS NOT implemented BY MYFACES THAT INSTEAD PERFORMS A STANDARD writer.write

        writer.write("\"");
    }
 ---------------------------------------------------------Myfaces Implementation--------------------------------------------------------
 public void writeURIAttribute(String name, Object value, String componentPropertyName)
        throws IOException
    {
        if(name == null)
            throw new NullPointerException("attributeName name must not be null");
        if(!_startTagOpen)
            throw new IllegalStateException("Must be called before the start element is closed (attribute '" + name + "')");
        String strValue = value.toString();
        _writer.write(32);
        _writer.write(name);
        _writer.write("=\"");
        if(strValue.toLowerCase().startsWith("javascript:"))
            _writer.write(HTMLEncoder.encode(strValue, false, false, !"UTF-8".equals(_characterEncoding)));
        else
            _writer.write(strValue);
        _writer.write(34);
    }



      was (Author: lcerulli):
    Just to give some additional information the text below comes form the JSF spec 1.2 maintenance release 2006 specification:

"public void writeAttribute(String name, Object value, String
componentPropertyName) throws IOException;

public void writeURIAttribute(String name, Object value, String
componentPropertyName) throws IOException;

These methods add an attribute name/value pair to an element that was opened with a
previous call to startElement(), throwing an exception if there is no currently open
element. The writeAttribute() method causes character encoding to be performed in
the same manner as that performed by the writeText() methods. The
writeURIAttribute() method assumes that the attribute value is a URI, and performs
URI encoding (such as % encoding for HTML)" -> Chapter 6-10 [page 210]

The important part is obviously the last sentence
Below you can find the R.I. implementation:

----------------------------------Reference implementation-------------------------------------------------------
   public void writeURIAttribute(String name, Object value, String componentPropertyName)
        throws IOException
    {
        if(name == null || value == null)
            throw new NullPointerException(Util.getExceptionMessageString("com.sun.faces.NULL_PARAMETERS_ERROR"));
        writer.write(" ");
        writer.write(name);
        writer.write("=\"");
        String stringValue = value.toString();
        if(stringValue.startsWith("javascript:"))
            HtmlUtils.writeAttribute(writer, buffer, stringValue);
        else

            HtmlUtils.writeURL(writer, stringValue, encoding);------->This IS NOT implemented BY MYFACES THAT INSTEAD PERFORMS A STANDARD writer.write

        writer.write("\"");
    }
 ---------------------------------------------------------Myfaces Implementation--------------------------------------------------------
 public void writeURIAttribute(String name, Object value, String componentPropertyName)
        throws IOException
    {
        if(name == null)
            throw new NullPointerException("attributeName name must not be null");
        if(!_startTagOpen)
            throw new IllegalStateException("Must be called before the start element is closed (attribute '" + name + "')");
        String strValue = value.toString();
        _writer.write(32);
        _writer.write(name);
        _writer.write("=\"");
        if(strValue.toLowerCase().startsWith("javascript:"))
            _writer.write(HTMLEncoder.encode(strValue, false, false, !"UTF-8".equals(_characterEncoding)));
        else
            _writer.write(strValue);
        _writer.write(34);
    }


  
> HtmlResponseWriterImpl.writeURIAttribute does not perform proper URLs encoding  ( ex: & should be encoded in &amp)
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: MYFACES-1841
>                 URL: https://issues.apache.org/jira/browse/MYFACES-1841
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: General, Portlet_Support
>    Affects Versions: 1.1.4, 1.1.5,  1.2.0
>         Environment: Windows xp sp2->Jboss portal  2.4.2->tomcat 5.5 ->JSF portlet 
>            Reporter: Lorenzo Cerulli
>
> HtmlFormRenderer is the class in charge of rendering the UIForm component and all the required attibutes.
> This class is in charge of rendering  for example the Form component  tinto <form id="foo" name="bar" action=/HelloWorldJSFPortletWindow?action=1&org.apache.myfaces.portlet.MyFacesGenericPortlet.VIEW_ID=%2FWEB-INF%2Fjsp%2Findex. .....> </form>
> During the rendering process the form renderer uses  HtmlResponseWriterImpl.writeURIAttribute to write the "action" attribute of the form component.
> Generally speaking the action attribute should be acquired using "context.getApplication().getViewHandler().getActionURL(context, viewid))" and the result  MUST be encoded using "context.getExternalContext().encodeActionURL" before passing the url to the "HtmlResponseWriterImpl.writeURIAttribute(URL);" This way the URL will be well formed and will be correctly encoded in the action attribute.
> Even if the HtmlFormRendererBase for example correctly implements this process the resulting URL is encoded in the action attribute without correctly transforming "&" in "&amp". 
> At this point we can argue that this bug could be generated by two different sources:
> 1. Not correct URL encding perfomed by javax.faces.context.FacesContext  during  context.getExternalContext().encodeActionURL[this is non related to myfaces and probably depend on the PortletResponse object implemented by the container JBOSS portal in this case]
> 2. Nor correct URI encoding within HtmlResponseWriterImpl.writeURIAttribute(URL) [related to myfaces]
> Analyzing the source code of the latter i noticed that writeURIAttribute(URL) internally calls the HTMLEncoder.encode method to perform string encoding if the URI starts with the "javascript" prefix otherwise does not perform any kind of encoding.
> Probably this is a bug bacause an enforcment of URI encoding rules should be provided in any case;

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


[jira] Updated: (MYFACES-1841) HtmlResponseWriterImpl.writeURIAttribute does not perform proper URLs encoding ( ex: & should be encoded in &)

Posted by "Leonardo Uribe (JIRA)" <de...@myfaces.apache.org>.
     [ https://issues.apache.org/jira/browse/MYFACES-1841?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Leonardo Uribe updated MYFACES-1841:
------------------------------------

       Resolution: Fixed
    Fix Version/s: 1.2.7-SNAPSHOT
                   1.1.7-SNAPSHOT
           Status: Resolved  (was: Patch Available)

> HtmlResponseWriterImpl.writeURIAttribute does not perform proper URLs encoding  ( ex: & should be encoded in &amp)
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: MYFACES-1841
>                 URL: https://issues.apache.org/jira/browse/MYFACES-1841
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: General, Portlet_Support
>    Affects Versions: 1.1.4, 1.1.5,  1.2.0
>         Environment: Windows xp sp2->Jboss portal  2.4.2->tomcat 5.5 ->JSF portlet 
>            Reporter: Lorenzo Cerulli
>            Assignee: Leonardo Uribe
>             Fix For: 1.1.7-SNAPSHOT, 1.2.7-SNAPSHOT
>
>         Attachments: MYFACES-1841-1.patch
>
>
> HtmlFormRenderer is the class in charge of rendering the UIForm component and all the required attibutes.
> This class is in charge of rendering  for example the Form component  tinto <form id="foo" name="bar" action=/HelloWorldJSFPortletWindow?action=1&org.apache.myfaces.portlet.MyFacesGenericPortlet.VIEW_ID=%2FWEB-INF%2Fjsp%2Findex. .....> </form>
> During the rendering process the form renderer uses  HtmlResponseWriterImpl.writeURIAttribute to write the "action" attribute of the form component.
> Generally speaking the action attribute should be acquired using "context.getApplication().getViewHandler().getActionURL(context, viewid))" and the result  MUST be encoded using "context.getExternalContext().encodeActionURL" before passing the url to the "HtmlResponseWriterImpl.writeURIAttribute(URL);" This way the URL will be well formed and will be correctly encoded in the action attribute.
> Even if the HtmlFormRendererBase for example correctly implements this process the resulting URL is encoded in the action attribute without correctly transforming "&" in "&amp". 
> At this point we can argue that this bug could be generated by two different sources:
> 1. Not correct URL encding perfomed by javax.faces.context.FacesContext  during  context.getExternalContext().encodeActionURL[this is non related to myfaces and probably depend on the PortletResponse object implemented by the container JBOSS portal in this case]
> 2. Nor correct URI encoding within HtmlResponseWriterImpl.writeURIAttribute(URL) [related to myfaces]
> Analyzing the source code of the latter i noticed that writeURIAttribute(URL) internally calls the HTMLEncoder.encode method to perform string encoding if the URI starts with the "javascript" prefix otherwise does not perform any kind of encoding.
> Probably this is a bug bacause an enforcment of URI encoding rules should be provided in any case;

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


[jira] Commented: (MYFACES-1841) HtmlResponseWriterImpl.writeURIAttribute does not perform proper URLs encoding ( ex: & should be encoded in &)

Posted by "Scott O'Bryan (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-1841?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12581633#action_12581633 ] 

Scott O'Bryan commented on MYFACES-1841:
----------------------------------------

Makes sense to me.  Seems to be something that the TCK should have caught though...

> HtmlResponseWriterImpl.writeURIAttribute does not perform proper URLs encoding  ( ex: & should be encoded in &amp)
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: MYFACES-1841
>                 URL: https://issues.apache.org/jira/browse/MYFACES-1841
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: General, Portlet_Support
>    Affects Versions: 1.1.4, 1.1.5,  1.2.0
>         Environment: Windows xp sp2->Jboss portal  2.4.2->tomcat 5.5 ->JSF portlet 
>            Reporter: Lorenzo Cerulli
>
> HtmlFormRenderer is the class in charge of rendering the UIForm component and all the required attibutes.
> This class is in charge of rendering  for example the Form component  tinto <form id="foo" name="bar" action=/HelloWorldJSFPortletWindow?action=1&org.apache.myfaces.portlet.MyFacesGenericPortlet.VIEW_ID=%2FWEB-INF%2Fjsp%2Findex. .....> </form>
> During the rendering process the form renderer uses  HtmlResponseWriterImpl.writeURIAttribute to write the "action" attribute of the form component.
> Generally speaking the action attribute should be acquired using "context.getApplication().getViewHandler().getActionURL(context, viewid))" and the result  MUST be encoded using "context.getExternalContext().encodeActionURL" before passing the url to the "HtmlResponseWriterImpl.writeURIAttribute(URL);" This way the URL will be well formed and will be correctly encoded in the action attribute.
> Even if the HtmlFormRendererBase for example correctly implements this process the resulting URL is encoded in the action attribute without correctly transforming "&" in "&amp". 
> At this point we can argue that this bug could be generated by two different sources:
> 1. Not correct URL encding perfomed by javax.faces.context.FacesContext  during  context.getExternalContext().encodeActionURL[this is non related to myfaces and probably depend on the PortletResponse object implemented by the container JBOSS portal in this case]
> 2. Nor correct URI encoding within HtmlResponseWriterImpl.writeURIAttribute(URL) [related to myfaces]
> Analyzing the source code of the latter i noticed that writeURIAttribute(URL) internally calls the HTMLEncoder.encode method to perform string encoding if the URI starts with the "javascript" prefix otherwise does not perform any kind of encoding.
> Probably this is a bug bacause an enforcment of URI encoding rules should be provided in any case;

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


[jira] Commented: (MYFACES-1841) HtmlResponseWriterImpl.writeURIAttribute does not perform proper URLs encoding ( ex: & should be encoded in &)

Posted by "Leonardo Uribe (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-1841?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12712850#action_12712850 ] 

Leonardo Uribe commented on MYFACES-1841:
-----------------------------------------

Patch attached with the proposed solution.

According to RFC 3986, an URI has the following structure:

URI         = scheme ":" hier-part [ "?" query ] [ "#" fragment ]

The patch follows the RFC 3986 (see comments inside patch)  to percent-encode the URI.

It converts caracters from 0x7F to infinitum from ' scheme ":" hier-part ' first to UTF-8 and then to percent encoding, as suggested by:

 -  RFC 3986 Section 3.2.2
 -  http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars

Then the remaining part ' [ "?" query ] [ "#" fragment ] ' is encoded using the current character encoding set in HtmlResponseWriterImpl, because this part contains data that is decoded by the servlet container (configure this part is servlet container specific ).

If no objections, I'll commit this code soon on both shared branches.

> HtmlResponseWriterImpl.writeURIAttribute does not perform proper URLs encoding  ( ex: & should be encoded in &amp)
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: MYFACES-1841
>                 URL: https://issues.apache.org/jira/browse/MYFACES-1841
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: General, Portlet_Support
>    Affects Versions: 1.1.4, 1.1.5,  1.2.0
>         Environment: Windows xp sp2->Jboss portal  2.4.2->tomcat 5.5 ->JSF portlet 
>            Reporter: Lorenzo Cerulli
>         Attachments: MYFACES-1841-1.patch
>
>
> HtmlFormRenderer is the class in charge of rendering the UIForm component and all the required attibutes.
> This class is in charge of rendering  for example the Form component  tinto <form id="foo" name="bar" action=/HelloWorldJSFPortletWindow?action=1&org.apache.myfaces.portlet.MyFacesGenericPortlet.VIEW_ID=%2FWEB-INF%2Fjsp%2Findex. .....> </form>
> During the rendering process the form renderer uses  HtmlResponseWriterImpl.writeURIAttribute to write the "action" attribute of the form component.
> Generally speaking the action attribute should be acquired using "context.getApplication().getViewHandler().getActionURL(context, viewid))" and the result  MUST be encoded using "context.getExternalContext().encodeActionURL" before passing the url to the "HtmlResponseWriterImpl.writeURIAttribute(URL);" This way the URL will be well formed and will be correctly encoded in the action attribute.
> Even if the HtmlFormRendererBase for example correctly implements this process the resulting URL is encoded in the action attribute without correctly transforming "&" in "&amp". 
> At this point we can argue that this bug could be generated by two different sources:
> 1. Not correct URL encding perfomed by javax.faces.context.FacesContext  during  context.getExternalContext().encodeActionURL[this is non related to myfaces and probably depend on the PortletResponse object implemented by the container JBOSS portal in this case]
> 2. Nor correct URI encoding within HtmlResponseWriterImpl.writeURIAttribute(URL) [related to myfaces]
> Analyzing the source code of the latter i noticed that writeURIAttribute(URL) internally calls the HTMLEncoder.encode method to perform string encoding if the URI starts with the "javascript" prefix otherwise does not perform any kind of encoding.
> Probably this is a bug bacause an enforcment of URI encoding rules should be provided in any case;

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


[jira] Issue Comment Edited: (MYFACES-1841) HtmlResponseWriterImpl.writeURIAttribute does not perform proper URLs encoding ( ex: & should be encoded in &)

Posted by "Lorenzo Cerulli (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-1841?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12581611#action_12581611 ] 

lcerulli edited comment on MYFACES-1841 at 3/24/08 11:30 AM:
--------------------------------------------------------------------

Just to give some additional information the text below comes form the JSF spec 1.2 maintenance release 2006 specification:

"public void writeAttribute(String name, Object value, String
componentPropertyName) throws IOException;

public void writeURIAttribute(String name, Object value, String
componentPropertyName) throws IOException;

These methods add an attribute name/value pair to an element that was opened with a
previous call to startElement(), throwing an exception if there is no currently open
element. The writeAttribute() method causes character encoding to be performed in
the same manner as that performed by the writeText() methods. The
writeURIAttribute() method assumes that the attribute value is a URI, and performs
URI encoding (such as % encoding for HTML)" -> Chapter 6-10 [page 210]

The important part is obviously the last sentence
Below you can find the R.I. implementation:

----------------------------------Reference implementation-------------------------------------------------------
   public void writeURIAttribute(String name, Object value, String componentPropertyName)
        throws IOException
    {
        if(name == null || value == null)
            throw new NullPointerException(Util.getExceptionMessageString("com.sun.faces.NULL_PARAMETERS_ERROR"));
        writer.write(" ");
        writer.write(name);
        writer.write("=\"");
        String stringValue = value.toString();
        if(stringValue.startsWith("javascript:"))
            HtmlUtils.writeAttribute(writer, buffer, stringValue);
        else

            HtmlUtils.writeURL(writer, stringValue, encoding);------->This IS NOT implemented BY MYFACES THAT INSTEAD PERFORMS A STANDARD writer.write

        writer.write("\"");
    }
 ---------------------------------------------------------Myfaces Implementation--------------------------------------------------------
 public void writeURIAttribute(String name, Object value, String componentPropertyName)
        throws IOException
    {
        if(name == null)
            throw new NullPointerException("attributeName name must not be null");
        if(!_startTagOpen)
            throw new IllegalStateException("Must be called before the start element is closed (attribute '" + name + "')");
        String strValue = value.toString();
        _writer.write(32);
        _writer.write(name);
        _writer.write("=\"");
        if(strValue.toLowerCase().startsWith("javascript:"))
            _writer.write(HTMLEncoder.encode(strValue, false, false, !"UTF-8".equals(_characterEncoding)));
        else
            _writer.write(strValue);
        _writer.write(34);
    }



      was (Author: lcerulli):
    Just to give some additional information the text below comes form the JSF spec 1.2 maintenance release 2006 specification:

"public void writeAttribute(String name, Object value, String
componentPropertyName) throws IOException;

public void writeURIAttribute(String name, Object value, String
componentPropertyName) throws IOException;

These methods add an attribute name/value pair to an element that was opened with a
previous call to startElement(), throwing an exception if there is no currently open
element. The writeAttribute() method causes character encoding to be performed in
the same manner as that performed by the writeText() methods. The
writeURIAttribute() method assumes that the attribute value is a URI, and performs
URI encoding (such as % encoding for HTML)" -> Chapter 6-10 [page 210]

The important part is obviously the last sentence

  
> HtmlResponseWriterImpl.writeURIAttribute does not perform proper URLs encoding  ( ex: & should be encoded in &amp)
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: MYFACES-1841
>                 URL: https://issues.apache.org/jira/browse/MYFACES-1841
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: General, Portlet_Support
>    Affects Versions: 1.1.4, 1.1.5,  1.2.0
>         Environment: Windows xp sp2->Jboss portal  2.4.2->tomcat 5.5 ->JSF portlet 
>            Reporter: Lorenzo Cerulli
>
> HtmlFormRenderer is the class in charge of rendering the UIForm component and all the required attibutes.
> This class is in charge of rendering  for example the Form component  tinto <form id="foo" name="bar" action=/HelloWorldJSFPortletWindow?action=1&org.apache.myfaces.portlet.MyFacesGenericPortlet.VIEW_ID=%2FWEB-INF%2Fjsp%2Findex. .....> </form>
> During the rendering process the form renderer uses  HtmlResponseWriterImpl.writeURIAttribute to write the "action" attribute of the form component.
> Generally speaking the action attribute should be acquired using "context.getApplication().getViewHandler().getActionURL(context, viewid))" and the result  MUST be encoded using "context.getExternalContext().encodeActionURL" before passing the url to the "HtmlResponseWriterImpl.writeURIAttribute(URL);" This way the URL will be well formed and will be correctly encoded in the action attribute.
> Even if the HtmlFormRendererBase for example correctly implements this process the resulting URL is encoded in the action attribute without correctly transforming "&" in "&amp". 
> At this point we can argue that this bug could be generated by two different sources:
> 1. Not correct URL encding perfomed by javax.faces.context.FacesContext  during  context.getExternalContext().encodeActionURL[this is non related to myfaces and probably depend on the PortletResponse object implemented by the container JBOSS portal in this case]
> 2. Nor correct URI encoding within HtmlResponseWriterImpl.writeURIAttribute(URL) [related to myfaces]
> Analyzing the source code of the latter i noticed that writeURIAttribute(URL) internally calls the HTMLEncoder.encode method to perform string encoding if the URI starts with the "javascript" prefix otherwise does not perform any kind of encoding.
> Probably this is a bug bacause an enforcment of URI encoding rules should be provided in any case;

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


[jira] Commented: (MYFACES-1841) HtmlResponseWriterImpl.writeURIAttribute does not perform proper URLs encoding ( ex: & should be encoded in &)

Posted by "Scott O'Bryan (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-1841?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12581530#action_12581530 ] 

Scott O'Bryan commented on MYFACES-1841:
----------------------------------------

How does the R.I. function for this behavior?

> HtmlResponseWriterImpl.writeURIAttribute does not perform proper URLs encoding  ( ex: & should be encoded in &amp)
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: MYFACES-1841
>                 URL: https://issues.apache.org/jira/browse/MYFACES-1841
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: General, Portlet_Support
>    Affects Versions: 1.1.4, 1.1.5,  1.2.0
>         Environment: Windows xp sp2->Jboss portal  2.4.2->tomcat 5.5 ->JSF portlet 
>            Reporter: Lorenzo Cerulli
>
> HtmlFormRenderer is the class in charge of rendering the UIForm component and all the required attibutes.
> This class is in charge of rendering  for example the Form component  tinto <form id="foo" name="bar" action=/HelloWorldJSFPortletWindow?action=1&org.apache.myfaces.portlet.MyFacesGenericPortlet.VIEW_ID=%2FWEB-INF%2Fjsp%2Findex. .....> </form>
> During the rendering process the form renderer uses  HtmlResponseWriterImpl.writeURIAttribute to write the "action" attribute of the form component.
> Generally speaking the action attribute should be acquired using "context.getApplication().getViewHandler().getActionURL(context, viewid))" and the result  MUST be encoded using "context.getExternalContext().encodeActionURL" before passing the url to the "HtmlResponseWriterImpl.writeURIAttribute(URL);" This way the URL will be well formed and will be correctly encoded in the action attribute.
> Even if the HtmlFormRendererBase for example correctly implements this process the resulting URL is encoded in the action attribute without correctly transforming "&" in "&amp". 
> At this point we can argue that this bug could be generated by two different sources:
> 1. Not correct URL encding perfomed by javax.faces.context.FacesContext  during  context.getExternalContext().encodeActionURL[this is non related to myfaces and probably depend on the PortletResponse object implemented by the container JBOSS portal in this case]
> 2. Nor correct URI encoding within HtmlResponseWriterImpl.writeURIAttribute(URL) [related to myfaces]
> Analyzing the source code of the latter i noticed that writeURIAttribute(URL) internally calls the HTMLEncoder.encode method to perform string encoding if the URI starts with the "javascript" prefix otherwise does not perform any kind of encoding.
> Probably this is a bug bacause an enforcment of URI encoding rules should be provided in any case;

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


[jira] Commented: (MYFACES-1841) HtmlResponseWriterImpl.writeURIAttribute does not perform proper URLs encoding ( ex: & should be encoded in &)

Posted by "Lorenzo Cerulli (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-1841?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12581611#action_12581611 ] 

Lorenzo Cerulli commented on MYFACES-1841:
------------------------------------------

Just to give some additional information the text below comes form the JSF spec 1.2 maintenance release 2006 specification:

"public void writeAttribute(String name, Object value, String
componentPropertyName) throws IOException;

public void writeURIAttribute(String name, Object value, String
componentPropertyName) throws IOException;

These methods add an attribute name/value pair to an element that was opened with a
previous call to startElement(), throwing an exception if there is no currently open
element. The writeAttribute() method causes character encoding to be performed in
the same manner as that performed by the writeText() methods. The
writeURIAttribute() method assumes that the attribute value is a URI, and performs
URI encoding (such as % encoding for HTML)" -> Chapter 6-10 [page 210]

The important part is obviously the last sentence


> HtmlResponseWriterImpl.writeURIAttribute does not perform proper URLs encoding  ( ex: & should be encoded in &amp)
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: MYFACES-1841
>                 URL: https://issues.apache.org/jira/browse/MYFACES-1841
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: General, Portlet_Support
>    Affects Versions: 1.1.4, 1.1.5,  1.2.0
>         Environment: Windows xp sp2->Jboss portal  2.4.2->tomcat 5.5 ->JSF portlet 
>            Reporter: Lorenzo Cerulli
>
> HtmlFormRenderer is the class in charge of rendering the UIForm component and all the required attibutes.
> This class is in charge of rendering  for example the Form component  tinto <form id="foo" name="bar" action=/HelloWorldJSFPortletWindow?action=1&org.apache.myfaces.portlet.MyFacesGenericPortlet.VIEW_ID=%2FWEB-INF%2Fjsp%2Findex. .....> </form>
> During the rendering process the form renderer uses  HtmlResponseWriterImpl.writeURIAttribute to write the "action" attribute of the form component.
> Generally speaking the action attribute should be acquired using "context.getApplication().getViewHandler().getActionURL(context, viewid))" and the result  MUST be encoded using "context.getExternalContext().encodeActionURL" before passing the url to the "HtmlResponseWriterImpl.writeURIAttribute(URL);" This way the URL will be well formed and will be correctly encoded in the action attribute.
> Even if the HtmlFormRendererBase for example correctly implements this process the resulting URL is encoded in the action attribute without correctly transforming "&" in "&amp". 
> At this point we can argue that this bug could be generated by two different sources:
> 1. Not correct URL encding perfomed by javax.faces.context.FacesContext  during  context.getExternalContext().encodeActionURL[this is non related to myfaces and probably depend on the PortletResponse object implemented by the container JBOSS portal in this case]
> 2. Nor correct URI encoding within HtmlResponseWriterImpl.writeURIAttribute(URL) [related to myfaces]
> Analyzing the source code of the latter i noticed that writeURIAttribute(URL) internally calls the HTMLEncoder.encode method to perform string encoding if the URI starts with the "javascript" prefix otherwise does not perform any kind of encoding.
> Probably this is a bug bacause an enforcment of URI encoding rules should be provided in any case;

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