Skip to content

Commit 64c5374

Browse files
committed
fix: update regex for overlay path and text to allow additional safe characters
1 parent 696105a commit 64c5374

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/url/builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { ImageKitOptions, UrlOptions } from "../interfaces";
22
import { ImageOverlay, SolidColorOverlay, SubtitleOverlay, TextOverlay, Transformation, VideoOverlay } from "../interfaces/Transformation";
33
import transformationUtils, { safeBtoa } from "../utils/transformation";
44
const TRANSFORMATION_PARAMETER = "tr";
5-
const SIMPLE_OVERLAY_PATH_REGEX = new RegExp('^[a-zA-Z0-9-._,/ ]*$')
6-
const SIMPLE_OVERLAY_TEXT_REGEX = new RegExp('^[a-zA-Z0-9-._, ]*$') // These characters are selected by testing actual URLs on both path and query parameters. If and when backend starts supporting wide range of characters, this regex should be updated to improve URL readability.
5+
const SIMPLE_OVERLAY_PATH_REGEX = new RegExp('^[a-zA-Z0-9-._/ ]*$')
6+
const SIMPLE_OVERLAY_TEXT_REGEX = new RegExp('^[a-zA-Z0-9-._ ]*$') // These characters are selected by testing actual URLs on both path and query parameters. If and when backend starts supporting wide range of characters, this regex should be updated to improve URL readability.
77

88
function removeTrailingSlash(str: string) {
99
if (typeof str == "string" && str[str.length - 1] == "/") {

test/url-generation/overlay.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,17 +318,17 @@ describe("Overlay encoding test cases", function () {
318318
expect(url).equal(`https://ik.imagekit.io/demo/tr:l-text,i-Manu,l-end/medium_cafe_B1iTdD0C.jpg`);
319319
});
320320

321-
it('Simple text overlay with spaces and comma, should use i instead of ie', function () {
321+
it('Simple text overlay with spaces and other safe characters, should use i instead of ie', function () {
322322
const url = imagekit.url({
323323
path: "/medium_cafe_B1iTdD0C.jpg",
324324
transformation: [{
325325
overlay: {
326326
type: "text",
327-
text: "alnum123-._, ",
327+
text: "alnum123-._ ",
328328
}
329329
}]
330330
});
331-
expect(url).equal(`https://ik.imagekit.io/demo/tr:l-text,i-${encodeURIComponent("alnum123-._, ")},l-end/medium_cafe_B1iTdD0C.jpg`);
331+
expect(url).equal(`https://ik.imagekit.io/demo/tr:l-text,i-${encodeURIComponent("alnum123-._ ")},l-end/medium_cafe_B1iTdD0C.jpg`);
332332
});
333333

334334
it('Non simple text overlay, should use ie instead of i', function () {

0 commit comments

Comments
 (0)