You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by "Kohei Nozaki (JIRA)" <ji...@apache.org> on 2015/04/29 08:27:06 UTC

[jira] [Updated] (ROL-2075) InitFilter#getAbsoluteUrl() returns wrong URL which got last character removed

     [ https://issues.apache.org/jira/browse/ROL-2075?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Kohei Nozaki updated ROL-2075:
------------------------------
    Attachment: ROL-2075.patch

I fixed and added a test, and did some refactoring to make testing easy. any feedback welcome.

> InitFilter#getAbsoluteUrl() returns wrong URL which got last character removed
> ------------------------------------------------------------------------------
>
>                 Key: ROL-2075
>                 URL: https://issues.apache.org/jira/browse/ROL-2075
>             Project: Apache Roller
>          Issue Type: Bug
>          Components: User Interface - General
>    Affects Versions: 5.1.2
>         Environment: Tomcat/7.0.54
>            Reporter: Kohei Nozaki
>            Assignee: Roller Unassigned
>            Priority: Minor
>         Attachments: ROL-2075.patch
>
>
> Roller produces wrong URLs that based on {{InitFilter#getAbsoluteUrl()}} in following situation:
> * {{site.absoluteurl}} is not set
> * Roller is deployed on "/" (as ROOT.war)
> * The first request after deployment comes as a HTTPS request to GET "/"
> Problematic code:
> {code:java}
> String fullUrl = null;
> if (!request.isSecure()) {
>     fullUrl = request.getRequestURL().toString();
> } else {
>     fullUrl = "http://" + request.getServerName()
>             + request.getContextPath();
> }
> {code}
> In the preceding block,
> * {{request.isSecure()}} returns true
> * {{request.getServerName()}} returns "localhost"
> * {{request.getContextPath()}} returns ""
> So now {{fullUrl}} is {{http://localhost}}. then here comes following block:
> {code:java}
> // if the uri is only "/" then we are basically done
> if ("/".equals(request.getRequestURI())) {
>     if (log.isDebugEnabled()) {
>         log.debug(fullUrl.substring(0, fullUrl.length() - 1));
>     }
>     return fullUrl.substring(0, fullUrl.length() - 1);
> }
> {code}
> {{request.getRequestURI()}} returns {{"/"}}. then following {{fullUrl.substring()}} truncates the last character, and now URL is {{http://localhos}}.
> DEBUG log (actual URLs are masked by ***):
> {noformat}
> INFO  2015-04-29 00:11:28,357 PreviewServlet:init - Initializing PreviewServlet
> DEBUG 2015-04-29 00:11:38,512 CharEncodingFilter:doFilter - Processing CharEncodingFilter
> DEBUG 2015-04-29 00:11:38,514 CharEncodingFilter:doFilter - Set request character encoding to UTF-8
> DEBUG 2015-04-29 00:11:38,568 BootstrapFilter:doFilter - Entered /
> DEBUG 2015-04-29 00:11:38,569 WebloggerConfig:getProperty - Fetching property [installation.type=auto]
> DEBUG 2015-04-29 00:11:38,569 PersistenceSessionFilter:doFilter - Entered /
> DEBUG 2015-04-29 00:11:38,569 InitFilter:getAbsoluteUrl - http://***.rhcloud.co
> DEBUG 2015-04-29 00:11:38,569 InitFilter:doFilter - relPath = 
> DEBUG 2015-04-29 00:11:38,570 InitFilter:doFilter - absPath = http://***.rhcloud.co
> DEBUG 2015-04-29 00:11:38,570 RequestMappingFilter:doFilter - entering
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)