diff --git a/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/LanguageNavigationImpl.java b/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/LanguageNavigationImpl.java index 8a4733289e..ad8e0bf4db 100644 --- a/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/LanguageNavigationImpl.java +++ b/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/LanguageNavigationImpl.java @@ -152,7 +152,12 @@ private Page getLocalizedPage(Page page, Page languageRoot) { Page localizedPage; String path = languageRoot.getPath(); String relativePath = page.getPath(); - if (relativePath.startsWith(path)) { + int indexOfStart = 0; + if (path.length() < relativePath.length()) { + indexOfStart = path.length(); + } + if (relativePath.startsWith(path) && + relativePath.charAt(indexOfStart) == '/') { localizedPage = page; } else { String separator = "/"; diff --git a/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v1/LanguageNavigationImplTest.java b/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v1/LanguageNavigationImplTest.java index 5a11b2cd9b..9e9cd9baef 100644 --- a/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v1/LanguageNavigationImplTest.java +++ b/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v1/LanguageNavigationImplTest.java @@ -68,6 +68,14 @@ public class LanguageNavigationImplTest { "/content/languagenavigation/LOCALE-4/LOCALE-9.html"}, }; + private static final Object[][] EXPECTED_COUNTRY_LIST = { + {"/content/countrytest/languagenavigation/ch", "ch", false, 0, "", "ch", + "/ch-3-vanity"}, + {"/content/countrytest/languagenavigation/ch_zn", "ch_zn", true, 0, "", "ch", + "/ch_zn-3-vanity"}, + {"/content/countrytest/languagenavigation/en", "en", false, 0, "", "en", "/en-3-vanity"}, + }; + protected final AemContext context = CoreComponentTestContext.newAemContext(); protected String testBase; @@ -152,6 +160,15 @@ protected void testLanguageNavigationItemsOnTemplate() { } + @Test + protected void testLanguageNavigationItemsWithExtendedCountryCode() { + context.load().json(testBase + "/test-content-country.json", "/content/countrytest"); + LanguageNavigation languageNavigation = getLanguageNavigationUnderTest( + "/content/countrytest/languagenavigation/ch_zn/jcr:content/root/languagenavigation-component-1"); + List items = getLanguageNavigationItems(languageNavigation); + verifyLanguageNavigationItems(EXPECTED_COUNTRY_LIST, items); + } + protected LanguageNavigation getLanguageNavigationUnderTest(String resourcePath) { Utils.enableDataLayer(context, true); context.currentResource(resourcePath); diff --git a/bundles/core/src/test/resources/languagenavigation/test-content-country.json b/bundles/core/src/test/resources/languagenavigation/test-content-country.json new file mode 100644 index 0000000000..10282fb67c --- /dev/null +++ b/bundles/core/src/test/resources/languagenavigation/test-content-country.json @@ -0,0 +1,49 @@ +{ + "languagenavigation": { + "jcr:primaryType": "cq:Page", + "jcr:content": { + "jcr:primaryType": "cq:PageContent", + "jcr:title": "Language Structure", + "jcr:created": "Mon Jul 10 2017 20:21:55 GMT+0200" + }, + "ch": { + "jcr:primaryType": "cq:Page", + "jcr:content": { + "jcr:primaryType": "cq:PageContent", + "jcr:title": "ch", + "jcr:created": "Mon Jul 10 2017 20:21:55 GMT+0200", + "sling:vanityPath": "/ch-3-vanity", + "jcr:language": "ch" + } + }, + "ch_zn": { + "jcr:primaryType": "cq:Page", + "jcr:content" : { + "jcr:primaryType": "cq:PageContent", + "jcr:title" : "ch_zn", + "jcr:created" : "Mon Jul 10 2017 20:21:55 GMT+0200", + "sling:vanityPath": "/ch_zn-3-vanity", + "jcr:language" : "ch", + "root" : { + "jcr:primaryType": "nt:unstructured", + "languagenavigation-component-1": { + "jcr:primaryType" : "nt:unstructured", + "sling:resourceType": "core/wcm/components/languagenavigation/v1/languagenavigation", + "navigationRoot" : "/content/countrytest/languagenavigation", + "structureDepth" : 1 + } + } + } + }, + "en": { + "jcr:primaryType": "cq:Page", + "jcr:content": { + "jcr:primaryType": "cq:PageContent", + "jcr:title": "en", + "jcr:created": "Mon Jul 10 2017 20:21:55 GMT+0200", + "sling:vanityPath": "/en-3-vanity", + "jcr:language": "en" + } + } + } +} diff --git a/bundles/core/src/test/resources/languagenavigation/v2/test-content-country.json b/bundles/core/src/test/resources/languagenavigation/v2/test-content-country.json new file mode 100644 index 0000000000..10282fb67c --- /dev/null +++ b/bundles/core/src/test/resources/languagenavigation/v2/test-content-country.json @@ -0,0 +1,49 @@ +{ + "languagenavigation": { + "jcr:primaryType": "cq:Page", + "jcr:content": { + "jcr:primaryType": "cq:PageContent", + "jcr:title": "Language Structure", + "jcr:created": "Mon Jul 10 2017 20:21:55 GMT+0200" + }, + "ch": { + "jcr:primaryType": "cq:Page", + "jcr:content": { + "jcr:primaryType": "cq:PageContent", + "jcr:title": "ch", + "jcr:created": "Mon Jul 10 2017 20:21:55 GMT+0200", + "sling:vanityPath": "/ch-3-vanity", + "jcr:language": "ch" + } + }, + "ch_zn": { + "jcr:primaryType": "cq:Page", + "jcr:content" : { + "jcr:primaryType": "cq:PageContent", + "jcr:title" : "ch_zn", + "jcr:created" : "Mon Jul 10 2017 20:21:55 GMT+0200", + "sling:vanityPath": "/ch_zn-3-vanity", + "jcr:language" : "ch", + "root" : { + "jcr:primaryType": "nt:unstructured", + "languagenavigation-component-1": { + "jcr:primaryType" : "nt:unstructured", + "sling:resourceType": "core/wcm/components/languagenavigation/v1/languagenavigation", + "navigationRoot" : "/content/countrytest/languagenavigation", + "structureDepth" : 1 + } + } + } + }, + "en": { + "jcr:primaryType": "cq:Page", + "jcr:content": { + "jcr:primaryType": "cq:PageContent", + "jcr:title": "en", + "jcr:created": "Mon Jul 10 2017 20:21:55 GMT+0200", + "sling:vanityPath": "/en-3-vanity", + "jcr:language": "en" + } + } + } +}