Repository: tapestry-5 Updated Branches: refs/heads/5.3 00e3ef4e9 -> 3a3ce1dab
TAP5-2424: Trim the applicationFolderPrefix for Event Request Use the same method used in Page Request for Event Request to remove the applicationFolderPrefix. Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/3a3ce1da Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/3a3ce1da Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/3a3ce1da Branch: refs/heads/5.3 Commit: 3a3ce1dabf3f2eee3714304887eb9d4c78c53f5c Parents: 00e3ef4 Author: Nicolas Bouillon <[email protected]> Authored: Fri Dec 5 11:09:40 2014 +0100 Committer: Jochen Kemnade <[email protected]> Committed: Mon Dec 8 17:41:03 2014 +0100 ---------------------------------------------------------------------- .../services/ComponentEventLinkEncoderImpl.java | 60 +++++++++----------- .../ComponentEventLinkEncoderImplTest.java | 37 +++++++++++- 2 files changed, 62 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3a3ce1da/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImpl.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImpl.java index c3c853b..020fd3b 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImpl.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImpl.java @@ -246,35 +246,22 @@ public class ComponentEventLinkEncoderImpl implements ComponentEventLinkEncoder return builder.toString(); } - private String peekFirst(List<String> path) - { - if (path.size() == 0) - { - return null; - } - - return path.get(0); - } - public ComponentEventRequestParameters decodeComponentEventRequest(Request request) { String explicitLocale = null; // Split the path around slashes into a mutable list of terms, which will be consumed term by term. - List<String> path = splitPath(request.getPath()); + String requestPath = request.getPath(); - if (this.applicationFolder.length() > 0) + if (applicationFolderPrefix != null) { - // TODO: Should this be case insensitive + requestPath = removeApplicationPrefix(requestPath); + } + + List<String> path = splitPath(requestPath); - String inPath = path.remove(0); - if (!inPath.equals(this.applicationFolder)) - { - return null; - } - } if (path.isEmpty()) { @@ -402,21 +389,7 @@ public class ComponentEventLinkEncoderImpl implements ComponentEventLinkEncoder if (applicationFolderPrefix != null) { - int prefixLength = applicationFolderPrefix.length(); - - assert path.substring(0, prefixLength).equalsIgnoreCase(applicationFolderPrefix); - - // This checks that the character after the prefix is a slash ... the extra complexity - // only seems to occur in Selenium. There's some ambiguity about what to do with a request for - // the application folder that doesn't end with a slash. Manuyal with Chrome and IE 8 shows that such - // requests are passed through with a training slash, automated testing with Selenium and FireFox - // can include requests for the folder without the trailing slash. - - assert path.length() <= prefixLength || path.charAt(prefixLength) == '/'; - - // Strip off the folder prefix (i.e., "/foldername"), leaving the rest of the path (i.e., "/en/pagename"). - - path = path.substring(prefixLength); + path = removeApplicationPrefix(path); } @@ -482,6 +455,25 @@ public class ComponentEventLinkEncoderImpl implements ComponentEventLinkEncoder return result; } + private String removeApplicationPrefix(String path) { + int prefixLength = applicationFolderPrefix.length(); + + assert path.substring(0, prefixLength).equalsIgnoreCase(applicationFolderPrefix); + + // This checks that the character after the prefix is a slash ... the extra complexity + // only seems to occur in Selenium. There's some ambiguity about what to do with a request for + // the application folder that doesn't end with a slash. Manuyal with Chrome and IE 8 shows that such + // requests are passed through with a training slash, automated testing with Selenium and FireFox + // can include requests for the folder without the trailing slash. + + assert path.length() <= prefixLength || path.charAt(prefixLength) == '/'; + + // Strip off the folder prefix (i.e., "/foldername"), leaving the rest of the path (i.e., "/en/pagename"). + + path = path.substring(prefixLength); + return path; + } + private PageRenderRequestParameters checkIfPage(Request request, String pageName, String pageActivationContext) { if (!componentClassResolver.isPageName(pageName)) http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3a3ce1da/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImplTest.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImplTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImplTest.java index 638be59..419c893 100644 --- a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImplTest.java +++ b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImplTest.java @@ -365,7 +365,6 @@ public class ComponentEventLinkEncoderImplTest extends InternalBaseTestCase verify(); } - @Test public void context_passed_in_path_without_final_slash() throws Exception { @@ -448,4 +447,40 @@ public class ComponentEventLinkEncoderImplTest extends InternalBaseTestCase verify(); } + + @Test + public void decode_compoent_event_request_with_slash_in_context_path() throws Exception + { + ComponentClassResolver resolver = mockComponentClassResolver(); + Request request = mockRequest(); + Response response = mockResponse(); + LocalizationSetter ls = mockLocalizationSetter(); + MetaDataLocator metaDataLocator = neverWhitelistProtected(); + + expect(ls.isSupportedLocaleName("page.component:event")).andReturn(false); + + train_getParameter(request, InternalConstants.PAGE_CONTEXT_NAME, null); + train_getParameter(request, InternalConstants.CONTAINER_PAGE_NAME, null); + train_getLocale(request, Locale.ENGLISH); + + ls.setNonPersistentLocaleFromLocaleName("en"); + + train_getPath(request, "/foo/bar/page.component:event"); + + train_isPageName(resolver, "page", true); + + train_canonicalizePageName(resolver, "page", "Page"); + + replay(); + + ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, + response, null, null, null, true, null, "foo/bar", metaDataLocator, null); + + ComponentEventRequestParameters parameters = linkEncoder.decodeComponentEventRequest(request); + assertNotNull(parameters); + assertEquals(parameters.getActivePageName(), "Page"); + assertEquals(parameters.getEventType(), "event"); + + verify(); + } }
