-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: encode filenames #539
Conversation
1fd62a0
to
d1815a9
Compare
d1815a9
to
676876f
Compare
Yes. The client should do the encode. The api should decode it before storing it in the db, and return the decoded version in responses, so the user doesn't see them. We need to add tests and to document that when using the /car and /upload enpoints directly you need to encode the file name, and that the client will do this for you. @zebateira are you up for trying out this fix on the api and client? we could pair on it some if that would help? |
@olizilla yeah sounds good 👍 |
7300e67
to
b195e5b
Compare
Updated:
In order to have a test on the api, I added the name to the return body: web3.storage/packages/api/src/car.js Line 215 in b195e5b
I don't think we can test this in another way because of the DB mock right? My intuition was to (1) upload (2) get files list (3) check filename is correct, but since we are not connected to the DB we can't do this? |
Right now this can't be tested fully on the preview link because it points to staging, so only after merging will we see this working fully. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, but I think we should not return the name in create just for testing purposes. Name is obtained in listUploads, so it seems like we are adding a test just because.
With this in mind, I think it would be more useful to just add to the mock response (here) a validation where if we receive an invalid name we throw an error instead of a "good" answer. This way, the test is just sending a name that needs to be encoded and validate it does not make it way to the DB request
@zebateira we should also document this. Not sure where it fits better, but perhaps adding information here and we also need the docs |
@vasco-santos yeah, the api test is not the best.
What do you mean add a validation in the mock response? A validation assertion in the mock response code here? web3.storage/packages/api/src/car.js Line 153 in b195e5b
|
In the mock server for the graphql post, you can access what data is sent in that post, which means you can inspect there the content of The two options are:
So two tests for the API to exercise both of these paths. In the mock server (condition that the performed operation is the createUpload), you can get the content of the name property from the request and do something like: const encoded = encodeURIComponent(name)
const decoded = decodeURIComponent(encoded)
if (decoded !== name) {
return gqlResponse(500, {
errors: [{ message: `error message` }]
})
} This will fail when you provide to the API a name such as |
c7a02a2
to
412ea40
Compare
@vasco-santos thank you for the help! |
412ea40
to
1b35fc6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I think it is better now 🎉 just another detail similar but for client testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good! Can we add docs for this to the API as Oli suggested?
f7019ac
to
75f3f12
Compare
Docs added! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR fixes upload not working on the website when the filename includes a non ISO-8859-1 character.
We were missing an encode/decodeURIComponent. This only affects the files because the filename is sent via header
X-NAME
.I made the fix in the
lib/api.js
file on the website code. Should this done on the js client instead?Fixes #532