Skip to content
Closed
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
4 changes: 2 additions & 2 deletions libs/url/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const buildURL = function (opts: FinalUrlOptions): string {
//string should be added only as a query parameter
if (transformationUtils.addAsQueryParameter(opts) || isSrcParameterUsedForURL) {
queryParameters.set(TRANSFORMATION_PARAMETER, transformationString);
urlObject.pathname= `${urlObject.pathname}${opts.path||''}`;
urlObject.pathname = path.posix.join(urlObject.pathname, opts.path || "");
} else {
urlObject.pathname = path.posix.join(
urlObject.pathname,
Expand All @@ -74,7 +74,7 @@ const buildURL = function (opts: FinalUrlOptions): string {
}
}
else{
urlObject.pathname= `${urlObject.pathname}${opts.path||''}`;
urlObject.pathname = path.posix.join(urlObject.pathname, opts.path || "");
}

urlObject.host = urlFormatter.removeTrailingSlash(urlObject.host);
Expand Down
13 changes: 13 additions & 0 deletions tests/url-generation.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,19 @@ describe("URL generation", function () {

});

it('should not duplicate slashes when urlEndpoint has trailing slash', function () {
const kit = new ImageKit({
...initializationParams,
urlEndpoint: initializationParams.urlEndpoint + '/',
});

const url = kit.url({
path: '/test_path.jpg'
});

expect(url).equal('https://ik.imagekit.io/test_url_endpoint/test_path.jpg');
});

it('should generate the correct url with path param with transformationPosition as query', function () {
const url = imagekit.url({
path: "/test_path.jpg",
Expand Down