incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asa...@apache.org
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 GMT
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<String, List<MapEntry>> entryMap, final String
key, final MapEntry entry) {
+    	if (entry==null){
+    		return;
+    	}
         List<MapEntry> entries = entryMap.get(key);
         if (entries == null) {
             entries = new ArrayList<MapEntry>();
@@ -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<String, List<String>> 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<String, MapEntry> 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");



Mime
View raw message