Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2AB1CEAE2 for ; Mon, 25 Feb 2013 08:47:27 +0000 (UTC) Received: (qmail 35638 invoked by uid 500); 25 Feb 2013 08:47:27 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 35573 invoked by uid 500); 25 Feb 2013 08:47:25 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 35521 invoked by uid 99); 25 Feb 2013 08:47:23 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Feb 2013 08:47:23 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Feb 2013 08:47:21 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id BDCDC2388980; Mon, 25 Feb 2013 08:47:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1449619 - in /sling/trunk/bundles/resourceresolver/src: main/java/org/apache/sling/resourceresolver/impl/mapping/ test/java/org/apache/sling/resourceresolver/impl/mapping/ Date: Mon, 25 Feb 2013 08:47:02 -0000 To: commits@sling.apache.org From: asanso@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130225084702.BDCDC2388980@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: asanso Date: Mon Feb 25 08:47:02 2013 New Revision: 1449619 URL: http://svn.apache.org/r1449619 Log: SLING-2741 - Bad Vanity URL breaks whole Sling Resource Resolver : - applied patch Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntry.java sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java?rev=1449619&r1=1449618&r2=1449619&view=diff ============================================================================== --- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java (original) +++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java Mon Feb 25 08:47:02 2013 @@ -462,6 +462,9 @@ public class MapEntries implements Event * Add an entry to the resolve map. */ private void addEntry(final Map> entryMap, final String key, final MapEntry entry) { + if (entry==null){ + return; + } List entries = entryMap.get(key); if (entries == null) { entries = new ArrayList(); @@ -588,19 +591,19 @@ public class MapEntries implements Event if (redirectName.indexOf('.') > -1) { // 1. entry with exact match - this.addEntry(entryMap, checkPath, new MapEntry(url + "$", status, false, redirect)); + this.addEntry(entryMap, checkPath, getMapEntry(url + "$", status, false, redirect)); final int idx = redirectName.lastIndexOf('.'); final String extension = redirectName.substring(idx + 1); // 2. entry with extension - this.addEntry(entryMap, checkPath, new MapEntry(url + "\\." + extension, status, false, redirect)); + this.addEntry(entryMap, checkPath, getMapEntry(url + "\\." + extension, status, false, redirect)); } else { // 1. entry with exact match - this.addEntry(entryMap, checkPath, new MapEntry(url + "$", status, false, redirect + ".html")); + this.addEntry(entryMap, checkPath, getMapEntry(url + "$", status, false, redirect + ".html")); // 2. entry with match supporting selectors and extension - this.addEntry(entryMap, checkPath, new MapEntry(url + "(\\..*)", status, false, redirect + "$1")); + this.addEntry(entryMap, checkPath, getMapEntry(url + "(\\..*)", status, false, redirect + "$1")); } // 3. keep the path to return targetPaths.add(redirect); @@ -666,7 +669,10 @@ public class MapEntries implements Event // this regular expression must match the whole URL !! final String url = "^" + ANY_SCHEME_HOST + extPath + "$"; final String redirect = intPath; - entries.add(new MapEntry(url, -1, false, redirect)); + MapEntry mapEntry = getMapEntry(url, -1, false, redirect); + if (mapEntry!=null){ + entries.add(mapEntry); + } } } } @@ -691,7 +697,10 @@ public class MapEntries implements Event } for (final Entry> entry : map.entrySet()) { - entries.add(new MapEntry(ANY_SCHEME_HOST + entry.getKey(), -1, false, entry.getValue().toArray(new String[0]))); + MapEntry mapEntry = getMapEntry(ANY_SCHEME_HOST + entry.getKey(), -1, false, entry.getValue().toArray(new String[0])); + if (mapEntry!=null){ + entries.add(mapEntry); + } } } } @@ -731,15 +740,17 @@ public class MapEntries implements Event private void addMapEntry(final Map entries, final String path, final String url, final int status) { MapEntry entry = entries.get(path); if (entry == null) { - entry = new MapEntry(path, status, false, url); + entry = getMapEntry(path, status, false, url); } else { final String[] redir = entry.getRedirect(); final String[] newRedir = new String[redir.length + 1]; System.arraycopy(redir, 0, newRedir, 0, redir.length); newRedir[redir.length] = url; - entry = new MapEntry(entry.getPattern(), entry.getStatus(), false, newRedir); + entry = getMapEntry(entry.getPattern(), entry.getStatus(), false, newRedir); + } + if (entry!=null){ + entries.put(path, entry); } - entries.put(path, entry); } /** @@ -866,4 +877,18 @@ public class MapEntries implements Event } } }; + + private MapEntry getMapEntry(String url, final int status, final boolean trailingSlash, + final String... redirect){ + + MapEntry mapEntry = null; + try{ + mapEntry = new MapEntry(url, status, trailingSlash, redirect); + }catch (IllegalArgumentException iae){ + //ignore this entry + log.debug("ignored entry due exception ",iae); + } + return mapEntry; + } + } Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntry.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntry.java?rev=1449619&r1=1449618&r2=1449619&view=diff ============================================================================== --- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntry.java (original) +++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntry.java Mon Feb 25 08:47:02 2013 @@ -237,8 +237,13 @@ public class MapEntry implements Compara if (!url.startsWith("^")) { url = "^".concat(url); } - - this.urlPattern = Pattern.compile(url); + + try { + this.urlPattern = Pattern.compile(url); + } catch (Exception e){ + throw new IllegalArgumentException("Bad url ",e); + } + this.redirect = redirect; this.status = status; } Modified: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java?rev=1449619&r1=1449618&r2=1449619&view=diff ============================================================================== --- sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java (original) +++ sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java Mon Feb 25 08:47:02 2013 @@ -150,6 +150,13 @@ public class MapEntriesTest { when(justVanityPath.getName()).thenReturn("justVanityPath"); when(justVanityPath.adaptTo(ValueMap.class)).thenReturn(buildValueMap("sling:vanityPath", "/target/justVanityPath")); resources.add(justVanityPath); + + Resource badVanityPath = mock(Resource.class); + when(badVanityPath.getPath()).thenReturn("/badVanityPath"); + when(badVanityPath.getName()).thenReturn("badVanityPath"); + when(badVanityPath.adaptTo(ValueMap.class)).thenReturn(buildValueMap("sling:vanityPath", "/content/mypage/en-us-{132")); + resources.add(badVanityPath); + Resource redirectingVanityPath = mock(Resource.class); when(redirectingVanityPath.getPath()).thenReturn("/redirectingVanityPath");