Closed mkbloke closed 2 years ago
@mkbloke Thank you for your feedback.
Since pathvalidate 2.5.0
, you can set null_value_handler
to sanitize_filename
function call.
This will change the function behavior when the value after sanitization is empty.
e.g. Raise exception when the value after sanitization is empty:
from pathvalidate import sanitize_filename, ValidationError
from pathvalidate.handler import raise_error
try:
sanitize_filename("/", null_value_handler=raise_error)
except ValidationError as e:
print(e)
reason=NULL_NAME, description=the value must be a not empty
The default behavior is not changed for now (return ""
).
Here's another example that doesn't do what I would expect (although perhaps I'm expecting the wrong thing?).
In pathvalidate 2.4.1:
That's what I would expect.
That's consistent with the character removal, but the end result is not a valid filename, so I would have expected
sanitize_filename()
to raise an error here?I can call
validate_filename()
aftersanitize_filename()
to take care of this. Is that what I should be doing, or should I be able to expect thatsanitize_filename()
either returns a usable filename or raises an error?Cheers.