Skip to content

Commit 19ef748

Browse files
frvgedanielcaldas
authored andcommitted
Support URL-encoded asset names in getBaseImageUrl (#9)
* Support URL-encoded asset names in getBaseImageUrl * Update CHANGELOG * Fix lint issues. Add prettier
1 parent ff4d37b commit 19ef748

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## master
44

5+
### Bugfix
6+
7+
- [#7](https://github.com/trivago/babel-plugin-cloudinary/issues/7) Support asset names in `getBaseImageUrl` that are URL-encoded by Cloudinary API.
8+
9+
### Features
10+
511
- Update dependencies based on npm's security audit
612

713
## [0.0.1](https://github.com/trivago/babel-plugin-cloudinary/tree/0.0.1)

lib/cloudinary-proxy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function getBaseImageUrl(assetName, transforms) {
3838
url = url.replace(BASE_URL_PLACEHOLDER, runConfig.host);
3939
}
4040

41-
return url.split(assetName)[0];
41+
return decodeURIComponent(url).split(assetName)[0];
4242
}
4343

4444
module.exports = {

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"jest": "^24.8.0",
5353
"lint-staged": "^8.1.3",
5454
"nodemon": "^1.18.9",
55+
"prettier": "^1.18.2",
5556
"typescript": "^3.2.4"
5657
},
5758
"repository": {

test/cloudinary-proxy.spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const { getBaseImageUrl } = require("../lib/cloudinary-proxy");
2+
3+
jest.mock(
4+
"../cloudinaryrc.json",
5+
() => ({
6+
native: {
7+
// eslint-disable-next-line camelcase
8+
cloud_name: "trivago",
9+
secure: true,
10+
},
11+
host: "trivago.images.com",
12+
overrideBaseUrl: true,
13+
}),
14+
{ virtual: true }
15+
);
16+
17+
describe("cloudinary-proxy", () => {
18+
it("has proper output for getBaseImageUrl 1", () => {
19+
const expected = "https://trivago.images.com/";
20+
21+
expect(getBaseImageUrl("myfile.jpg")).toEqual(expected);
22+
});
23+
24+
it("has proper output for getBaseImageUrl 2", () => {
25+
const expected = "https://trivago.images.com/";
26+
27+
expect(getBaseImageUrl("[email protected]")).toEqual(expected);
28+
});
29+
});

0 commit comments

Comments
 (0)