Skip to content
Merged
Show file tree
Hide file tree
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
32 changes: 32 additions & 0 deletions __TESTS__/unit/analytics/analytics.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,36 @@ describe('Add analytics to a regular URL', () => {
}
});
});

it('Should not include analytics key when publicId ends with a question mark', () => {
const cldImage = createNewImageWithAnalytics('sample?');
// AZ -> Algo A, SDK Code is Z
// Alh -> 1.24.0 from package.json
// AM -> 12.0.0 Underlying tech
// A -> responsive
expect(cldImage.toURL({
trackedAnalytics: {
sdkCode: 'Z',
sdkSemver: '1.24.0',
techVersion: '12.0.0',
responsive: true
}
})).toBe("https://res.cloudinary.com/demo/image/upload/sample%3F");
});

it('Should not include analytics key when publicId includes a question mark', () => {
const cldImage = createNewImageWithAnalytics('sample?param=test');
// AZ -> Algo A, SDK Code is Z
// Alh -> 1.24.0 from package.json
// AM -> 12.0.0 Underlying tech
// A -> responsive
expect(cldImage.toURL({
trackedAnalytics: {
sdkCode: 'Z',
sdkSemver: '1.24.0',
techVersion: '12.0.0',
responsive: true
}
})).toBe("https://res.cloudinary.com/demo/image/upload/sample%3Fparam%3Dtest");
});
});
2 changes: 1 addition & 1 deletion src/assets/CloudinaryFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class CloudinaryFile {
.replace(/=/g, '%3D');

// True by default, has to be explicitly set to false to overwrite
if (this.urlConfig.analytics !== false) {
if (this.urlConfig.analytics !== false && !(publicID.includes('?'))) {
return `${safeURL}?_a=${getSDKAnalyticsSignature(trackedAnalytics)}`;
} else {
return safeURL;
Expand Down