Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#27516 fixing the way to capture the inode from an url #27517

Merged
merged 5 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 28 additions & 1 deletion dotCMS/src/main/java/com/dotmarketing/filters/CMSUrlUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.dotmarketing.util.PageMode;
import com.dotmarketing.util.UtilMethods;
import com.liferay.portal.model.User;
import com.liferay.util.StringPool;
import com.liferay.util.Xss;
import io.vavr.Tuple;
import io.vavr.Tuple2;
Expand All @@ -38,6 +39,8 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -62,6 +65,8 @@ public class CMSUrlUtil {
private static final String NOT_FOUND = "NOTFOUND";
private static final String UNABLE_TO_FIND = "Unable to find ";

private static final Pattern INODE_PATTERN = Pattern.compile("/[a-f0-9]+-[a-f0-9]+-[a-f0-9]+-[a-f0-9]+-[a-f0-9]+/");

public static final Set<String> BACKEND_FILTERED_COLLECTION =
Stream.of("/api", "/webdav", "/dA", "/c/", "/contentAsset", "/DOTSASS", "/DOTLESS",
"/html", "/dotAdmin", "/custom-elements","/dotcms-webcomponents","/dwr")
Expand Down Expand Up @@ -590,14 +595,36 @@ public static String getCurrentURI(final HttpServletRequest request) {
* @return The Inode of the Contentlet.
*/
public String getInodeFromUrlPath(final String urlPath) {

// tries the edit mode first
final PageMode[] modes = PageMode.values();
for (final PageMode mode : modes) {
if (urlPath.startsWith(FORWARD_SLASH + mode.name() + FORWARD_SLASH)) {
final String urlPathWithoutMode = urlPath.substring(mode.name().length() + 2);
return urlPathWithoutMode.substring(0, urlPathWithoutMode.indexOf(FORWARD_SLASH));
}
}

// tries the fe mode: /data/shared/assets/c/e/ce837ff5-dc6f-427a-8f60-d18afc395be9/fileAsset/openai-summarize.vtl
final Optional<String> inodeOPt = findInodeFromString(urlPath);
if (inodeOPt.isPresent()) {
return inodeOPt.get();
}

// tries the content mode: CONTENT/27e8f845c3bd21ad1c601b8fe005caa6_1695072095296.content
return urlPath.substring(urlPath.indexOf(FORWARD_SLASH) + 1, urlPath.indexOf(UNDERLINE));
}

}
private Optional<String> findInodeFromString(final String someString) {

final Matcher matcher = INODE_PATTERN.matcher(someString);

if (matcher.find()) {
final String inode = matcher.group().replace(FORWARD_SLASH, StringPool.BLANK);
return Optional.ofNullable(inode);
}

return Optional.empty();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public void test_getIdentifierFromUrlPath() {
final String contentIdentifier2 = CMSUrlUtil.getInstance().getInodeFromUrlPath(templateUrlPath);
assertNotNull(contentIdentifier2);
assertEquals("27e8f845c3bd21ad1c601b8fe005caa6", contentIdentifier2);

final String feUrlPath = "/data/shared/assets/c/e/ce837ff5-dc6f-427a-8f60-d18afc395be9/fileAsset/openai-summarize.vtl";
final String contentIdentifier3 = CMSUrlUtil.getInstance().getInodeFromUrlPath(feUrlPath);
assertNotNull(contentIdentifier3);
assertEquals("ce837ff5-dc6f-427a-8f60-d18afc395be9", contentIdentifier3);
}

}