StringIndexOutOfBoundsException in AbstractItem.getUrl (#8481)

This commit is contained in:
Jesse Glick authored and GitHub committed 2023-09-20 20:42:26 +02:00
1 parent 41cd7992eb
commit 2a07b98e9c
2 files changed
+13 -3

No files matched your search

@@ -555,9 +555,15 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet
View view = (View) last.getObject();
if (view.getOwner().getItemGroup() == getParent() && !view.isDefault()) {
// Showing something inside a view, so should use that as the base URL.
String base = last.getUrl().substring(req.getContextPath().length() + 1) + '/';
LOGGER.log(Level.FINER, "using {0}{1} for {2} from {3}", new Object[] {base, shortUrl, this, uri});
return base + shortUrl;
String prefix = req.getContextPath() + "/";
String url = last.getUrl();
if (url.startsWith(prefix)) {
String base = url.substring(prefix.length()) + '/';
LOGGER.log(Level.FINER, "using {0}{1} for {2} from {3} given {4}", new Object[] {base, shortUrl, this, uri, prefix});
return base + shortUrl;
} else {
LOGGER.finer(() -> url + " does not start with " + prefix + " as expected");
}
} else {
LOGGER.log(Level.FINER, "irrelevant {0} for {1} from {2}", new Object[] {view.getViewName(), this, uri});
}