Skip to content

Commit

Permalink
feat: attached files referenced via Data URLs are ignored in auto-sha…
Browse files Browse the repository at this point in the history
…ring (#519)
  • Loading branch information
adubovik authored Oct 11, 2024
1 parent e4ef368 commit 9be9a9b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/epam/aidial/core/data/ResourceType.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static ResourceType of(String group) {
case "invitations" -> INVITATION;
case "publications" -> PUBLICATION;
case "applications" -> APPLICATION;
default -> throw new IllegalArgumentException("Unsupported group: " + group);
default -> throw new IllegalArgumentException("Unsupported resource type: " + group);
};
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/epam/aidial/core/function/BaseFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public BaseFunction(Proxy proxy, ProxyContext context) {

@SneakyThrows
public static ResourceDescription fromAnyUrl(String url, EncryptionService encryption) {
if (url == null || UrlUtil.isAbsoluteUrl(url)) {
// second check to skip public resource
if (url == null || UrlUtil.isAbsoluteUrl(url) || UrlUtil.isDataUrl(url)) {
// skipping public resources and Data URLs
return null;
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/epam/aidial/core/util/UrlUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@ public String decodePath(String path, boolean checkUri) {
public boolean isAbsoluteUrl(String url) {
return ABSOLUTE_URL_PATTERN.matcher(url).find();
}

public boolean isDataUrl(String url) {
return url.startsWith("data:");
}
}
11 changes: 11 additions & 0 deletions src/test/java/com/epam/aidial/core/util/UrlUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,15 @@ public void testIsAbsoluteUrl() {
assertFalse(UrlUtil.isAbsoluteUrl("/example/file.txt"));
assertFalse(UrlUtil.isAbsoluteUrl("file"));
}

@Test
public void testIsDataUrl() {
assertTrue(UrlUtil.isDataUrl("data:whatever"));
assertTrue(UrlUtil.isDataUrl("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAADCAIAAADZSiLoAAAAF0lEQVR4nGNkYPjPwMDAwMDAxAADCBYAG10BBdmz9y8AAAAASUVORK5CYII="));
assertFalse(UrlUtil.isDataUrl("data"));
assertFalse(UrlUtil.isDataUrl("DATA:whatever"));
assertFalse(UrlUtil.isDataUrl(" data:whatever"));
assertFalse(UrlUtil.isDataUrl("data;whatever"));
assertFalse(UrlUtil.isDataUrl("https://example.com"));
}
}

0 comments on commit 9be9a9b

Please sign in to comment.