Skip to content

Commit

Permalink
Merge pull request #603 from cloudinary/smd-number-field-fix
Browse files Browse the repository at this point in the history
fix: smd number field allows both numbers and string when uploading
  • Loading branch information
cloudinary-pkoniu authored Apr 27, 2023
2 parents 896ef01 + 3501d8b commit 607afb0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ function encode_context(metadataObj) {
return `\"${escapeMetadataValue(innerVal)}\"`
}).join(',');
return `${key}=[${values}]`
// if number, convert to string
} else if (Number.isInteger(value)) {
return `${key}=${escapeMetadataValue(String(value))}`;
// if unknown, return the value as string
} else {
return value.toString();
Expand Down
26 changes: 26 additions & 0 deletions test/integration/api/uploader/uploader_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,32 @@ describe("uploader", function () {
expect(result.metadata[METADATA_FIELD_UNIQUE_EXTERNAL_ID]).to.eql(METADATA_FIELD_VALUE);
});
});
it('should allow passing both string and a number for a number smd field', () => {
const smdNumberField = 'smd_number_field';
cloudinary.v2.api.add_metadata_field({
external_id: smdNumberField,
label: smdNumberField,
type: 'number'
}).then(() => {
return Promise.all([
uploadImage({
tags: UPLOAD_TAGS,
metadata: {
[smdNumberField]: 123
}
}),
uploadImage({
tags: UPLOAD_TAGS,
metadata: {
[smdNumberField]: '123'
}
})
]);
}).then(([firstUpload, secondUpload]) => {
expect(firstUpload.metadata[smdNumberField]).to.eql(123);
expect(secondUpload.metadata[smdNumberField]).to.eql(123);
});
});
it("should be updatable with uploader.update_metadata on an existing resource", function () {
let publicId;
return uploadImage({
Expand Down

0 comments on commit 607afb0

Please sign in to comment.