Tapestry 5
  1. Tapestry 5
  2. TAP5-653

Appending a context to an URL of the Index page results in too many slashes

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 5.1.0.3
    • Fix Version/s: 5.1.0.4
    • Component/s: tapestry-core
    • Labels:
      None

      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);
      }
      }

        Activity

        Igor Drobiazko created issue -
        Igor Drobiazko made changes -
        Field Original Value New Value
        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("/"))
                    {
                        builder.append(SLASH);
                    }
                    builder.append(encoded);
                }
            }
        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);
                }
            }
        Howard M. Lewis Ship made changes -
        Assignee Howard M. Lewis Ship [ hlship ]
        Howard M. Lewis Ship made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Howard M. Lewis Ship made changes -
        Status In Progress [ 3 ] Closed [ 6 ]
        Fix Version/s 5.1.0.4 [ 12313854 ]
        Resolution Fixed [ 1 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open In Progress In Progress
        12h 12m 1 Howard M. Lewis Ship 17/Apr/09 23:32
        In Progress In Progress Closed Closed
        25m 34s 1 Howard M. Lewis Ship 17/Apr/09 23:57

          People

          • Assignee:
            Howard M. Lewis Ship
            Reporter:
            Igor Drobiazko
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development