Skip to content

Commit b328f8a

Browse files
spudstuffAdam Nelson
andauthored
Escape all instances of single and double quotes, not just the first - fixes #504 (#505)
Co-authored-by: Adam Nelson <[email protected]>
1 parent 4bce081 commit b328f8a

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

lib-es5/utils/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ function join_pair(key, value) {
12611261
* @return {*} Encoded string or original value if not a string
12621262
*/
12631263
function escapeQuotes(value) {
1264-
return isString(value) ? value.replace('"', '&#34;').replace("'", '&#39;') : value;
1264+
return isString(value) ? value.replace(/\"/g, '&#34;').replace(/\'/g, '&#39;') : value;
12651265
}
12661266

12671267
/**

lib/utils/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ function join_pair(key, value) {
11581158
* @return {*} Encoded string or original value if not a string
11591159
*/
11601160
function escapeQuotes(value) {
1161-
return isString(value) ? value.replace('"', '&#34;').replace("'", '&#39;') : value;
1161+
return isString(value) ? value.replace(/\"/g, '&#34;').replace(/\'/g, '&#39;') : value;
11621162
}
11631163

11641164
/**

test/unit/tags/image_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ describe('image helper', function () {
121121
});
122122
it("should escape quotes in html attributes", function() {
123123
expect(cloudinary.image("sample.jpg", {
124-
alt: "asdfg\"'asdf"
125-
})).to.eql(`<img src='${UPLOAD_PATH}/sample.jpg' alt='asdfg&#34;&#39;asdf'/>`);
124+
alt: "here 'is' my \"alt\" escaped"
125+
})).to.eql(`<img src='${UPLOAD_PATH}/sample.jpg' alt='here &#39;is&#39; my &#34;alt&#34; escaped'/>`);
126126
});
127127

128128
describe(":client_hints", function () {

0 commit comments

Comments
 (0)