-
Notifications
You must be signed in to change notification settings - Fork 13
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: Allow disabling file name sanitization #1586
fix: Allow disabling file name sanitization #1586
Conversation
194c053
to
c35efeb
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.
👍
* @returns {Promise<object>} - A promise that returns the copied file if resolved. | ||
* @throws {FetchError} | ||
* | ||
*/ | ||
async copy(id, name, dirId) { | ||
async copy(id, name, dirId, { sanitizeName = true } = {}) { |
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.
An alternative would have been to pass a function rather than a bool, like:
{ sanitizeFct = sanitizeAndValidateFileName } = {}
And then:
if (sanitizeFct) { sanitizeFct(name) }
Not a big deal but I find it a bit more elegant than using a boolean
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.
It would open up some use cases but I don't find copy(id, name, dirId, { sanitizeFct: undefined })
that elegant.
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.
Maybe sanitizeFct: () => {}
would be better ? 😄
Anyways, I'm ok with both solutions, it's a matter of preference, so not a requirement to me
c35efeb
to
89f840f
Compare
Some clients, like Cozy Desktop, do their own file name sanitization and don't expect `cozy-client` to do it for them. In fact, this sanitization would lead to issues down the road. To prevent these, we add a `sanitizeName` option to `FileCollection`'s methods to disable `cozy-client`'s sanitization. The option's value will be `true` by default so other clients don't have anything to do.
89f840f
to
454d28b
Compare
async copy(id, name, dirId) { | ||
async copy(id, name, dirId, { sanitizeName = true } = {}) { | ||
let sanitizedName = name | ||
if (sanitizedName != null && sanitizeName) { |
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.
You slightly changed the condition here, from === undefined
to != null
. Is there a reason ?
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 is a habit I have because usually, when we don't want undefined
, we don't want null
either. And in this case, sanitizing null
would throw TypeError: Cannot read properties of null (reading 'trim')
.
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.
Ok, thanks
Some clients, like Cozy Desktop, do their own file name sanitization
and don't expect
cozy-client
to do it for them. In fact, thissanitization would lead to issues down the road.
To prevent these, we add a
sanitizeName
option toFileCollection
'smethods to disable
cozy-client
's sanitization.The option's value will be
true
by default so other clients don'thave anything to do.