You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by di...@apache.org on 2022/02/11 15:06:10 UTC
[sling-org-apache-sling-resourceresolver] 03/03: Fix MapEntry#replace() handling invalid substitutions
This is an automated email from the ASF dual-hosted git repository.
diru pushed a commit to branch issue/SLING-11138
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git
commit a645bca9f8f23e04c56166c2eff1385dc3bebb4f
Author: Dirk Rudolph <dr...@adobe.com>
AuthorDate: Fri Feb 11 16:05:57 2022 +0100
Fix MapEntry#replace() handling invalid substitutions
---
.../sling/resourceresolver/impl/mapping/MapEntry.java | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntry.java b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntry.java
index 67553d8..1d595a1 100644
--- a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntry.java
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntry.java
@@ -279,7 +279,7 @@ public class MapEntry implements Comparable<MapEntry> {
final Matcher m = urlPattern.matcher(value);
if (m.find()) {
final String[] redirects = getRedirect();
- final String[] results = new String[redirects.length];
+ final List<String> results = new ArrayList<>(redirects.length);
for (int i = 0; i < redirects.length; i++) {
try {
String redirect = redirects[i];
@@ -298,14 +298,12 @@ public class MapEntry implements Comparable<MapEntry> {
}
}
}
- results[i] = m.replaceFirst(redirect);
- } catch (final StringIndexOutOfBoundsException siob){
- log.debug("Exception while replacing, ignoring entry {} ", redirects[i], siob);
- } catch (final IllegalArgumentException iae){
- log.debug("Exception while replacing, ignoring entry {} ", redirects[i], iae);
- }
+ results.add(m.replaceFirst(redirect));
+ } catch (final StringIndexOutOfBoundsException | IllegalArgumentException ex){
+ log.debug("Exception while replacing, ignoring entry {} ", redirects[i], ex);
+ }
}
- return results;
+ return results.size() > 0 ? results.toArray(new String[0]) : null;
}
return null;