Skip to content

Commit 50c014e

Browse files
committed
Bug fix URL generation without any transformation was adding a empty tr:
1 parent c402113 commit 50c014e

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [1.3.2]
5+
- Bug fix URL generation without any transformation was adding a empty tr:
6+
47
## [1.3.1]
58
- Only urlEndpoint is required during SDK initilization
69

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "imagekit-javascript",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"description": "Javascript SDK for using ImageKit.io in the browser",
55
"main": "dist/imagekit.cjs.js",
66
"module": "dist/imagekit.esm.js",

src/url/builder.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const buildURL = (opts) => {
99
var urlObj, isSrcParameterUsedForURL, urlEndpointPattern;
1010
if (opts.path) {
1111
urlEndpointPattern = new URL(opts.urlEndpoint).pathname;
12-
urlObj = new URL(pathJoin([opts.urlEndpoint.replace(urlEndpointPattern,""),opts.path]));
12+
urlObj = new URL(pathJoin([opts.urlEndpoint.replace(urlEndpointPattern, ""), opts.path]));
1313
} else {
1414
urlObj = new URL(opts.src);
1515
isSrcParameterUsedForURL = true;
@@ -26,16 +26,18 @@ export const buildURL = (opts) => {
2626

2727
var transformationString = constructTransformationString(opts.transformation);
2828

29-
if (transformationUtils.addAsQueryParameter(opts) || isSrcParameterUsedForURL) {
30-
urlObj.searchParams.append(TRANSFORMATION_PARAMETER, transformationString);
31-
} else {
32-
urlObj.pathname = pathJoin([
33-
TRANSFORMATION_PARAMETER + transformationUtils.getChainTransformDelimiter() + transformationString,
34-
urlObj.pathname
35-
]);
29+
if (transformationString && transformationString.length) {
30+
if (transformationUtils.addAsQueryParameter(opts) || isSrcParameterUsedForURL) {
31+
urlObj.searchParams.append(TRANSFORMATION_PARAMETER, transformationString);
32+
} else {
33+
urlObj.pathname = pathJoin([
34+
TRANSFORMATION_PARAMETER + transformationUtils.getChainTransformDelimiter() + transformationString,
35+
urlObj.pathname
36+
]);
37+
}
3638
}
3739

38-
urlObj.pathname = pathJoin([urlEndpointPattern,urlObj.pathname]);
40+
urlObj.pathname = pathJoin([urlEndpointPattern, urlObj.pathname]);
3941

4042
return urlObj.href;
4143
}

test/url-generation.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ describe("URL generation", function () {
99

1010
var imagekit = new ImageKit(initializationParams);
1111

12+
it('no transformation path', function () {
13+
const url = imagekit.url({
14+
path: "/test_path.jpg"
15+
});
16+
17+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/test_path.jpg?ik-sdk-version=javascript-${pkg.version}`);
18+
});
19+
20+
it('no transformation src', function () {
21+
const url = imagekit.url({
22+
src: "https://ik.imagekit.io/test_url_endpoint/test_path_alt.jpg"
23+
});
24+
25+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/test_path_alt.jpg?ik-sdk-version=javascript-${pkg.version}`);
26+
});
27+
1228
it('should generate the correct url with path param', function () {
1329
const url = imagekit.url({
1430
path: "/test_path.jpg",

0 commit comments

Comments
 (0)