Skip to content

Commit 8b1a683

Browse files
author
Nir Maoz
authored
Disable analytics for publicId with question mark (#483)
1 parent 24811f9 commit 8b1a683

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

__TESTS__/unit/analytics/analytics.node.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,36 @@ describe('Add analytics to a regular URL', () => {
137137
}
138138
});
139139
});
140+
141+
it('Should not include analytics key when publicId ends with a question mark', () => {
142+
const cldImage = createNewImageWithAnalytics('sample?');
143+
// AZ -> Algo A, SDK Code is Z
144+
// Alh -> 1.24.0 from package.json
145+
// AM -> 12.0.0 Underlying tech
146+
// A -> responsive
147+
expect(cldImage.toURL({
148+
trackedAnalytics: {
149+
sdkCode: 'Z',
150+
sdkSemver: '1.24.0',
151+
techVersion: '12.0.0',
152+
responsive: true
153+
}
154+
})).toBe("https://res.cloudinary.com/demo/image/upload/sample%3F");
155+
});
156+
157+
it('Should not include analytics key when publicId includes a question mark', () => {
158+
const cldImage = createNewImageWithAnalytics('sample?param=test');
159+
// AZ -> Algo A, SDK Code is Z
160+
// Alh -> 1.24.0 from package.json
161+
// AM -> 12.0.0 Underlying tech
162+
// A -> responsive
163+
expect(cldImage.toURL({
164+
trackedAnalytics: {
165+
sdkCode: 'Z',
166+
sdkSemver: '1.24.0',
167+
techVersion: '12.0.0',
168+
responsive: true
169+
}
170+
})).toBe("https://res.cloudinary.com/demo/image/upload/sample%3Fparam%3Dtest");
171+
});
140172
});

src/assets/CloudinaryFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ class CloudinaryFile {
284284
.replace(/=/g, '%3D');
285285

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

0 commit comments

Comments
 (0)