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

Igor Drobiazko updated TAP5-653:
--------------------------------

    Description: 
When creating a page link to the Index page with a context, Tapestry creates a 
link with two slashes after the context path
Example:  /app//123

Because LinkImpl uses RequestPathOptimizer.optimizePath() inside the methode 
toUri() the url is optimized  to 123. So the link to the Index page will work.

But when you write a test for a page Foo (which contains a link to Index page) 
with PageTester, the test will fail because RequestPathOptimizer does not cut 
the url. The optimizer skips the optimization because in tests you can not use 
SymbolConstants.FORCE_ABSOLUTE_URIS = false. PagesTestes throws an exception if 
a path does not start with context path.

<t:pagelink page="Index" context="123">...</t:pagelink>


To fix the problem we have to check inside 
ComponentEventLinkEncoderImpl.appendContext() if the url ends with a slash.

    public void appendContext(EventContext context, StringBuilder builder)
    {
        String encoded = contextPathEncoder.encodeIntoPath(context);

        if (encoded.length() > 0)
        {
            if(!encoded.endsWith(SLASH))
            {
                builder.append(SLASH); 
            }
            builder.append(encoded);
        }
    }


  was:
When creating a page link to the Index page with a context, Tapestry creates a 
link with two slashes after the context path
Example:  /app//123

Because LinkImpl uses RequestPathOptimizer.optimizePath() inside the methode 
toUri() the url is optimized  to 123. So the link to the Index page will work.

But when you write a test for a page Foo (which contains a link to Index page) 
with PageTester, the test will fail because RequestPathOptimizer does not cut 
the url. The optimizer skips the optimization because in tests you can not use 
SymbolConstants.FORCE_ABSOLUTE_URIS = false. PagesTestes throws an exception if 
a path does not start with context path.

<t:pagelink page="Index" context="123">...</t:pagelink>


To fix the problem we have to check inside 
ComponentEventLinkEncoderImpl.appendContext() if the url ends with a slash.

    public void appendContext(EventContext context, StringBuilder builder)
    {
        String encoded = contextPathEncoder.encodeIntoPath(context);

        if (encoded.length() > 0)
        {
            if(encoded.endsWith("/"))
            {
                builder.append(SLASH); 
            }
            builder.append(encoded);
        }
    }



> Appending a context to an URL of the Index page results in too many slashes
> ---------------------------------------------------------------------------
>
>                 Key: TAP5-653
>                 URL: https://issues.apache.org/jira/browse/TAP5-653
>             Project: Tapestry 5
>          Issue Type: Bug
>          Components: tapestry-core
>    Affects Versions: 5.1.0.3
>            Reporter: Igor Drobiazko
>            Priority: Critical
>
> When creating a page link to the Index page with a context, Tapestry creates 
> a link with two slashes after the context path
> Example:  /app//123
> Because LinkImpl uses RequestPathOptimizer.optimizePath() inside the methode 
> toUri() the url is optimized  to 123. So the link to the Index page will work.
> But when you write a test for a page Foo (which contains a link to Index 
> page) with PageTester, the test will fail because RequestPathOptimizer does 
> not cut the url. The optimizer skips the optimization because in tests you 
> can not use SymbolConstants.FORCE_ABSOLUTE_URIS = false. PagesTestes throws 
> an exception if a path does not start with context path.
> <t:pagelink page="Index" context="123">...</t:pagelink>
> To fix the problem we have to check inside 
> ComponentEventLinkEncoderImpl.appendContext() if the url ends with a slash.
>     public void appendContext(EventContext context, StringBuilder builder)
>     {
>         String encoded = contextPathEncoder.encodeIntoPath(context);
>         if (encoded.length() > 0)
>         {
>             if(!encoded.endsWith(SLASH))
>             {
>                 builder.append(SLASH); 
>             }
>             builder.append(encoded);
>         }
>     }

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

Reply via email to