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

SAK-50554 Site Import Fails to Import Some Embedded Images #12937

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@

@Slf4j
public class LinkMigrationHelperImpl implements LinkMigrationHelper {
private static final String ESCAPED_SPACE= "%"+"20";
private static final String[] shortenerDomainsToExpand = {"/x/", "bit.ly"};
private static final String ESCAPED_SPACE = "%"+"20";
private static final String[] ENCODED_IMAGE = {"data:image"};
private static final String[] SHORTENER_STRINGS = {"/x/", "bit.ly"};

private ServerConfigurationService serverConfigurationService;

Expand Down Expand Up @@ -192,8 +193,8 @@ private String expandShortenedUrls(String msgBody){
}

for(String reference : references){
//If doesn't contain the prefix /x/, should ignore the URL.
if(referenceContainsShortenerDomains(reference)){
//If doesn't contain the prefix /x/ or is an encoded image, should ignore the URL.
if(!referenceContainsEncodedImage(reference) && referenceContainsShortenerDomains(reference)){
String longUrl = this.expandShortenedUrl(reference);
replacedBody = StringUtils.replace(replacedBody, reference, longUrl);
}
Expand All @@ -202,8 +203,12 @@ private String expandShortenedUrls(String msgBody){
return replacedBody;
}

private boolean referenceContainsEncodedImage(String reference) {
return Arrays.stream(ENCODED_IMAGE).anyMatch(reference::contains);
}

private boolean referenceContainsShortenerDomains(String reference) {
return Arrays.stream(shortenerDomainsToExpand).anyMatch(reference::contains);
return Arrays.stream(SHORTENER_STRINGS).anyMatch(reference::contains);
}

private String expandShortenedUrl(String shortenedUrl){
Expand Down
Loading