Skip to content

Commit ef16531

Browse files
committed
Add trailing slash test and revert to yarn classic
1 parent 85c7ef3 commit ef16531

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

libs/url/builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const buildURL = function (opts: FinalUrlOptions): string {
6464
//string should be added only as a query parameter
6565
if (transformationUtils.addAsQueryParameter(opts) || isSrcParameterUsedForURL) {
6666
queryParameters.set(TRANSFORMATION_PARAMETER, transformationString);
67-
urlObject.pathname= `${urlObject.pathname}${opts.path||''}`;
67+
urlObject.pathname = path.posix.join(urlObject.pathname, opts.path || "");
6868
} else {
6969
urlObject.pathname = path.posix.join(
7070
urlObject.pathname,
@@ -74,7 +74,7 @@ const buildURL = function (opts: FinalUrlOptions): string {
7474
}
7575
}
7676
else{
77-
urlObject.pathname= `${urlObject.pathname}${opts.path||''}`;
77+
urlObject.pathname = path.posix.join(urlObject.pathname, opts.path || "");
7878
}
7979

8080
urlObject.host = urlFormatter.removeTrailingSlash(urlObject.host);

tests/url-generation.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,19 @@ describe("URL generation", function () {
177177

178178
});
179179

180+
it('should not duplicate slashes when urlEndpoint has trailing slash', function () {
181+
const kit = new ImageKit({
182+
...initializationParams,
183+
urlEndpoint: initializationParams.urlEndpoint + '/',
184+
});
185+
186+
const url = kit.url({
187+
path: '/test_path.jpg'
188+
});
189+
190+
expect(url).equal('https://ik.imagekit.io/test_url_endpoint/test_path.jpg');
191+
});
192+
180193
it('should generate the correct url with path param with transformationPosition as query', function () {
181194
const url = imagekit.url({
182195
path: "/test_path.jpg",

0 commit comments

Comments
 (0)