Add encodeUriComponent to file name#967
Conversation
Fix for non standard file names (with spaces, apostrophes, etc) that prevent to be used.
src/components/widgets/FileWidget.js
Outdated
| import { dataURItoBlob, shouldRender, setState } from "../../utils"; | ||
|
|
||
| function addNameToDataURL(dataURL, name) { | ||
| name=encodeURIComponent(name) |
There was a problem hiding this comment.
you've got a lint error here.
Do this instead:
function addNameToDataURL(dataURL, name) {
return dataURL.replace(";base64", `;name=${encodeURIComponent(name)};base64`);
}There was a problem hiding this comment.
Sorry @graingert, did not see your comment until now.
epicfaace
left a comment
There was a problem hiding this comment.
@jorgerobles Thanks for the PR! Do you still plan to work on this? In addition to the lint error, I would suggest you also add a test.
jorgerobles
left a comment
There was a problem hiding this comment.
Forgot to fix it 🤦♂️
|
Great, thanks @jorgerobles ! Can you also add a test? It would be similar to the tests already existing: https://github.com/mozilla-services/react-jsonschema-form/blob/1941e760d8af93b118bbc193dd98b88f64b32645/test/StringField_test.js#L1503 |
|
@epicfaace I've added the test. I'm not very familiarised with mocha, hope is well. |
|
@jorgerobles Thanks, almost there -- instead of modifying the existing test, can you leave the existing test case "should reflect the change into the dom" in place and add a new test case right next to it? (you can copy and paste the existing test case and make the changes that you did) |
test/StringField_test.js
Outdated
| describe("FileWidget", () => { | ||
| const initialValue = "data:text/plain;name=file1.txt;base64,dGVzdDE="; | ||
|
|
||
| const nonUriEncodedValue = "fileáéí óú1.txt"; |
There was a problem hiding this comment.
Please move these two lines inside the "should encode file name with encodeURIComponent" test case.
|
Thank you, @jorgerobles ! |
|
You're welcome :) it's a great project!
El dom., 20 ene. 2019 18:21, Ashwin Ramaswami <notifications@github.com>
escribió:
… Thank you, @jorgerobles <https://github.com/jorgerobles> !
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#967 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABoIYL_EZU2Hh0KIqwftS1_bNv6bI3_kks5vFKWqgaJpZM4U98M_>
.
|
|
@jorgerobles can you help with #824? It's pretty similar to this one. |
Reasons for making this change
Fix for non standard file names (with spaces, apostrophes, etc) that prevent to be used.
For example uploading a whitespace named file prevents to be used as background url.
Checklist
npm run cs-formaton my branch to conform my code to prettier coding style