Skip to content

Commit

Permalink
#merge
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjgonzalez committed Sep 15, 2021
2 parents 75ee22b + c1bd43c commit 7a8071d
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 48 deletions.
20 changes: 17 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,27 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [v2.1.6]
## [v2.1.10]

### Fixed

- 0652 - Fixed over-escaping of static rendition paths (stemming from #639)
- 0653 - 6.5 only - Bundle does not start on 6.5.9
- 0654 - 6.5 only - ExternalRenditionDispatcher expression evaluation does not resolve to correct asset resource
- 0655 - 6.5 only - Erring HTTP POST is made on all page loads

## [v2.1.8]

### Fixed

- 0643 - Site title shows up the component policy title if not authored on header component policy
- 0639 - Correct issue introduced in 2.1.0 via #639 where URLs were being over-escaped breaking External Redirect Disaptching


## [v2.1.6]

### Fixed

- 0639 - Fixed regression introduced in #639 that over-escaped URLs

## [v2.1.4]

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>com.adobe.aem.commons</groupId>
<artifactId>assetshare</artifactId>
<version>2.1.5-SNAPSHOT</version>
<version>2.1.9-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 3 additions & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>com.adobe.aem.commons</groupId>
<artifactId>assetshare</artifactId>
<version>2.1.5-SNAPSHOT</version>
<version>2.1.9-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>assetshare.core</artifactId>
Expand Down Expand Up @@ -57,6 +57,8 @@ Import-Package: javax.annotation;version=0.0.0, \
com.day.cq.search.eval;version="[1.4.0,2)", \
org.apache.commons.io;version="[2.6.0,4)", \
org.apache.commons.lang3;version="[3.9.0,4)", \
org.osgi.framework;version="[1.9.0,2)", \
org.apache.sling.api.wrappers;version="[2.6.4,3)", \
*
-conditionalpackage: com.adobe.acs.commons.util.*,
-exportcontents: ${packages;VERSIONED}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@

import com.adobe.aem.commons.assetshare.util.UrlUtil;
import com.day.text.Text;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.utils.URIUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Optional;

/**
Expand All @@ -40,16 +42,21 @@ public class AssetRendition {
private String mimeType;

public AssetRendition(URI uri, Long size, String mimeType) {
setBinaryUri(uri);
setSize(size);
setMimeType(mimeType);
this(uri.toString(), size, mimeType);

}

public AssetRendition(String uri, Long size, String mimeType) {
URI cleanURI = null;

uri = UrlUtil.escape(uri, true);
try {
cleanURI = cleanURI(uri.toString());
} catch (URISyntaxException e) {
log.warn("Unable to clean the URI [ {} ], using it as is.", uri, e);
cleanURI = URI.create(uri);
}

setBinaryUri(URI.create(uri));
setBinaryUri(cleanURI);
setSize(size);
setMimeType(mimeType);
}
Expand Down Expand Up @@ -84,6 +91,12 @@ public void setMimeType(String mimeType) {
this.mimeType = mimeType;
}

private URI cleanURI(String uri) throws URISyntaxException {
uri = StringUtils.replace(uri, " ", "%20");
uri = StringUtils.replace(uri, "/_jcr_content", "/jcr:content");

return new URI(uri);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Map<String, String> getOptions(final Map<String, ? extends Object> mappin

@Override
public String evaluateExpression(final SlingHttpServletRequest request, String expression) {
final AssetModel assetModel = request.adaptTo(AssetModel.class);
final AssetModel assetModel = modelFactory.createModel(request.getResource(), AssetModel.class);
return evaluateExpression(assetModel, new AssetRenditionParameters(request).getRenditionName(), expression);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public String cleanURI(String uri) throws URISyntaxException {
.filter(nvp -> !QUERY_PARAM_SUGGESTED_EXTENSION.equals(nvp.getName()))
.forEach(nvp -> newURI.addParameter(nvp.getName(), nvp.getValue()));;

// Common pattern in DM URLS; This escaping probably is not necessary, but keeping for
// now as it would take a closer look to remove (and it breaks tests)
return StringUtils.replace(newURI.toString(), "%24", "$");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,25 @@ public static final String escape(final String unescaped, final boolean preventD
// URL cannot handle spaces, so convert them to %20; escapePath(..) will handle converting them back for later escaping
tmp = StringUtils.replace(tmp, " ", "%20");

try {
final URL url = new URL(tmp);
String path = escapePath(url.getPath());
if (!isPath(unescaped)) {
try {
final URL url = new URL(tmp);
String path = escapePath(url.getPath());

if (StringUtils.isNotBlank(url.getQuery())) {
path += "?" + url.getQuery();
}
if (StringUtils.isNotBlank(url.getQuery())) {
path += "?" + url.getQuery();
}

// Reconstruct the URL using the escaped path
return new URL(url.getProtocol(), url.getHost(), url.getPort(), path).toString();
// Reconstruct the URL using the escaped path
return new URL(url.getProtocol(), url.getHost(), url.getPort(), path).toString();

} catch (MalformedURLException e) {
// Treat as internal path
log.debug("Could not evaluate unescaped string [ {} ] as a URL. Falling back to escape as path.", e);
return escapePath(tmp);
} catch (MalformedURLException e) {
// Treat as internal path
log.debug("Could not evaluate unescaped string [ {} ] as a URL. Falling back to escape as path.", unescaped, e);
}
}

return escapePath(tmp);
}

/**
Expand Down Expand Up @@ -117,4 +120,20 @@ private static String escapePath(String path) {
path = Text.escapePath(path);
return path;
}

/**
* @param candidate the candidate URI to path to check
* @return true if it looks like a path, and false it looks like a URL
*/
private static boolean isPath(String candidate) {
if (StringUtils.isNotBlank(candidate)) {
if (candidate.matches("^[a-zA-Z0-9]+://.+")) {
return false;
} else if (StringUtils.startsWith(candidate, "//")) {
return false;
}
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ public void getBinaryUri() {
assetRendition = new AssetRendition("/content/dam/test asset.jpg", 123L, "image/jpeg");
assertEquals("/content/dam/test%20asset.jpg", assetRendition.getBinaryUri().toString());

assetRendition = new AssetRendition("/content/dam/test asset.jpg/jcr:content/renditions.cq5dam.web.1.2.png", 123L, "image/jpeg");
assertEquals("/content/dam/test%20asset.jpg/jcr:content/renditions.cq5dam.web.1.2.png", assetRendition.getBinaryUri().toString());

assetRendition = new AssetRendition("/content/dam/test+with+plus.jpg", 123L, "image/jpeg");
assertEquals("/content/dam/test%2bwith%2bplus.jpg", assetRendition.getBinaryUri().toString());
assertEquals("/content/dam/test+with+plus.jpg", assetRendition.getBinaryUri().toString());

assetRendition = new AssetRendition("https://test.com/content/dam/test asset.jpg", 123L, "image/jpeg");
assertEquals("https://test.com/content/dam/test%20asset.jpg", assetRendition.getBinaryUri().toString());

assetRendition = new AssetRendition("https://smartimaging.scene7.com/is/image/DynamicMediaNA/test (test):Medium", 123L, "image/jpeg");
assertEquals("https://smartimaging.scene7.com/is/image/DynamicMediaNA/test%20(test)%3aMedium", assetRendition.getBinaryUri().toString());
assertEquals("https://smartimaging.scene7.com/is/image/DynamicMediaNA/test%20(test):Medium", assetRendition.getBinaryUri().toString());

assetRendition = new AssetRendition("https://smartimaging.scene7.com/is/image/DynamicMediaNA/test (test)?$grayscale$", 123L, "image/jpeg");
assertEquals("https://smartimaging.scene7.com/is/image/DynamicMediaNA/test%20(test)?$grayscale$", assetRendition.getBinaryUri().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public class ExternalRedirectRenditionDispatcherImplTest {
public void setUp() throws Exception {
ctx.load().json(getClass().getResourceAsStream("ExternalRedirectRenditionDispatcherImplTest.json"), "/content/dam");
ctx.currentResource("/content/dam/test.png");
doReturn(DamUtil.resolveToAsset(ctx.resourceResolver().getResource("/content/dam/test.png"))).when(assetResolver).resolveAsset(ctx.request());

ctx.registerService(MimeTypeService.class, mimeTypeService);
ctx.registerService(ExpressionEvaluator.class, new ExpressionEvaluatorImpl());
Expand Down Expand Up @@ -161,7 +160,6 @@ public void dispatch() throws IOException, ServletException {
assetRenditionDispatcher.dispatch(ctx.request(), ctx.response());

assertEquals(301, ctx.response().getStatus());
//assertEquals("http://test.scene7.com/is/image/testing/test?%24greyscale%24", ctx.response().getHeader("Location"));
}

@Test
Expand All @@ -175,7 +173,6 @@ public void dispatch_WithSpacesInPath() throws IOException, ServletException {

final AssetRenditionDispatcher assetRenditionDispatcher = ctx.getService(AssetRenditionDispatcher.class);

doReturn(DamUtil.resolveToAsset(ctx.resourceResolver().getResource("/content/dam/test with spaces.png"))).when(assetResolver).resolveAsset(ctx.request());
ctx.currentResource("/content/dam/test with spaces.png");
ctx.requestPathInfo().setExtension("rendition");
ctx.requestPathInfo().setSuffix("testing/download/asset.rendition");
Expand All @@ -198,7 +195,6 @@ public void dispatch_WithHostAndSpacesInPath() throws IOException, ServletExcept

final AssetRenditionDispatcher assetRenditionDispatcher = ctx.getService(AssetRenditionDispatcher.class);

doReturn(DamUtil.resolveToAsset(ctx.resourceResolver().getResource("/content/dam/test with spaces.png"))).when(assetResolver).resolveAsset(ctx.request());
ctx.currentResource("/content/dam/test with spaces.png");
ctx.requestPathInfo().setExtension("rendition");
ctx.requestPathInfo().setSuffix("testing/download/asset.rendition");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public void setUp() throws Exception {

ctx.load().json(getClass().getResourceAsStream("InternalRedirectRenditionDispatcherImplTest.json"), "/content/dam");
ctx.currentResource("/content/dam/test.png");
doReturn(DamUtil.resolveToAsset(ctx.resourceResolver().getResource("/content/dam/test.png"))).when(assetResolver).resolveAsset(ctx.request());

ctx.registerService(MimeTypeService.class, mimeTypeService);
ctx.registerService(ExpressionEvaluator.class, new ExpressionEvaluatorImpl());
Expand Down Expand Up @@ -206,7 +205,6 @@ public void dispatch_WithSpacesInPath() throws IOException, ServletException {

final AssetRenditionDispatcher assetRenditionDispatcher = ctx.getService(AssetRenditionDispatcher.class);

doReturn(DamUtil.resolveToAsset(ctx.resourceResolver().getResource("/content/dam/test with spaces.png"))).when(assetResolver).resolveAsset(ctx.request());
ctx.currentResource("/content/dam/test with spaces.png");
ctx.requestPathInfo().setExtension("rendition");
ctx.requestPathInfo().setSuffix("testing/download/asset.rendition");
Expand Down
2 changes: 1 addition & 1 deletion dispatcher/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.adobe.aem.commons</groupId>
<artifactId>assetshare</artifactId>
<version>2.1.5-SNAPSHOT</version>
<version>2.1.9-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<groupId>com.adobe.aem.commons</groupId>
<artifactId>assetshare</artifactId>
<packaging>pom</packaging>
<version>2.1.5-SNAPSHOT</version>
<version>2.1.9-SNAPSHOT</version>

<name>Asset Share Commons - Reactor Project</name>
<description>asset-share-commons</description>
Expand Down
2 changes: 1 addition & 1 deletion ui.apps.structure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.adobe.aem.commons</groupId>
<artifactId>assetshare</artifactId>
<version>2.1.5-SNAPSHOT</version>
<version>2.1.9-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion ui.apps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>com.adobe.aem.commons</groupId>
<artifactId>assetshare</artifactId>
<version>2.1.5-SNAPSHOT</version>
<version>2.1.9-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,21 @@ jQuery((function($, ns, semanticModal, download) {
}

function updateBadge() {
$.post(DOWNLOADS_URL, getModalData()).then(function(htmlResponse) {
var count = ns.Elements.element('downloads-modal', htmlResponse).data('asset-share-downloads-count') || 0;
ns.Elements.element("downloads-count").text(count);
});
if (DOWNLOADS_URL) {
$.post(DOWNLOADS_URL, getModalData()).then(function(htmlResponse) {
var count = ns.Elements.element('downloads-modal', htmlResponse).data('asset-share-downloads-count') || 0;
ns.Elements.element("downloads-count").text(count);
});
}
}

function update() {
$.post(DOWNLOADS_URL, getModalData()).then(function(htmlResponse) {
ns.Elements.update(htmlResponse, WHEN_DOWNLOADS_UPDATED);
init();
});
if (DOWNLOADS_URL) {
$.post(DOWNLOADS_URL, getModalData()).then(function(htmlResponse) {
ns.Elements.update(htmlResponse, WHEN_DOWNLOADS_UPDATED);
init();
});
}
}

function show(e) {
Expand Down
2 changes: 1 addition & 1 deletion ui.content.sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>com.adobe.aem.commons</groupId>
<artifactId>assetshare</artifactId>
<version>2.1.5-SNAPSHOT</version>
<version>2.1.9-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion ui.content/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>com.adobe.aem.commons</groupId>
<artifactId>assetshare</artifactId>
<version>2.1.5-SNAPSHOT</version>
<version>2.1.9-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion ui.frontend.theme.dark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>com.adobe.aem.commons</groupId>
<artifactId>assetshare</artifactId>
<version>2.1.5-SNAPSHOT</version>
<version>2.1.9-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion ui.frontend.theme.light/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>com.adobe.aem.commons</groupId>
<artifactId>assetshare</artifactId>
<version>2.1.5-SNAPSHOT</version>
<version>2.1.9-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down

0 comments on commit 7a8071d

Please sign in to comment.