Skip to content

Commit 397d05d

Browse files
christensenepbc-alexsaiannyi
authored andcommitted
fix: SD-9364 Use CDN Original images for webdav - cache control
1 parent f8b3347 commit 397d05d

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

helpers/lib/cdnify.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ module.exports = globals => {
5656
}
5757

5858
if (protocol === 'webdav:') {
59-
return [cdnUrl, 'content', path].join('/');
59+
const supportedImageExtensions = ['jpg', 'jpeg', 'gif', 'png'];
60+
const unsupportedPathSyntaxes = ['../', './'];
61+
const isImage = supportedImageExtensions.some(ext => path.toLowerCase().includes(ext));
62+
const isTraversedPathUsed = unsupportedPathSyntaxes.some(syntax => path.startsWith(syntax));
63+
// to avoid breaking changes, we keep paths for webdav content unchanged if the path is traversed
64+
const prefix = isImage && !isTraversedPathUsed ? 'images/stencil/original/content' : 'content'
65+
return [cdnUrl, prefix, path].join('/');
6066
}
6167

6268
if (cdnSettings) {

spec/helpers/cdn.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,40 @@ describe('cdn helper', function () {
194194
], done);
195195
});
196196

197-
it('should return a webDav asset if webdav protocol specified', function (done) {
197+
it('should return an original cdn img asset if webdav protocol specified but file type indicates it is an image', function (done) {
198198
runTestCases([
199199
{
200200
input: '{{cdn "webdav:img/image.jpg"}}',
201-
output: 'https://cdn.bcapp/3dsf74g/content/img/image.jpg',
201+
output: 'https://cdn.bcapp/3dsf74g/images/stencil/original/content/img/image.jpg',
202202
},
203203
{
204-
input: '{{cdn "webdav:/img/image.jpg"}}',
205-
output: 'https://cdn.bcapp/3dsf74g/content/img/image.jpg',
204+
input: '{{cdn "webdav:/img/image.jpeg"}}',
205+
output: 'https://cdn.bcapp/3dsf74g/images/stencil/original/content/img/image.jpeg',
206206
},
207207
{
208-
input: '{{cdn "webdav://img/image.jpg"}}',
209-
output: 'https://cdn.bcapp/3dsf74g/content/img/image.jpg',
208+
input: '{{cdn "webdav://img/image.gif"}}',
209+
output: 'https://cdn.bcapp/3dsf74g/images/stencil/original/content/img/image.gif',
210+
},
211+
{
212+
input: '{{cdn "webdav://img/image.png"}}',
213+
output: 'https://cdn.bcapp/3dsf74g/images/stencil/original/content/img/image.png',
214+
},
215+
], done);
216+
});
217+
218+
it('should return a webDav asset if webdav protocol specified but is not a supported image type', function (done) {
219+
runTestCases([
220+
{
221+
input: '{{cdn "webdav:img/image.pdf"}}',
222+
output: 'https://cdn.bcapp/3dsf74g/content/img/image.pdf',
223+
},
224+
{
225+
input: '{{cdn "webdav:/img/image.pdf"}}',
226+
output: 'https://cdn.bcapp/3dsf74g/content/img/image.pdf',
227+
},
228+
{
229+
input: '{{cdn "webdav://img/image.pdf"}}',
230+
output: 'https://cdn.bcapp/3dsf74g/content/img/image.pdf',
210231
},
211232
], done);
212233
});

0 commit comments

Comments
 (0)