Skip to content
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: ensure automatically generated filename is a valid filename #27

Merged
merged 8 commits into from
Feb 11, 2024

Conversation

Monirzadeh
Copy link

@Monirzadeh Monirzadeh commented Feb 7, 2024

some characters are not valid in some os like ? in windows.
we check filename and replace that kind of charachter with - so ``go-epub` always use valid filename in any os.
Fix #26
@fmartingr can you please test this in shiori before we merge that too?
if it is ok i will just add more unit test to cover all characters in test too

@codecov-commenter
Copy link

codecov-commenter commented Feb 7, 2024

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (2f66845) 83.37% compared to head (7080e4d) 82.87%.

Files Patch % Lines
epub.go 52.63% 4 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #27      +/-   ##
==========================================
- Coverage   83.37%   82.87%   -0.51%     
==========================================
  Files          10       10              
  Lines        1209     1226      +17     
==========================================
+ Hits         1008     1016       +8     
- Misses        141      145       +4     
- Partials       60       65       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fmartingr
Copy link
Member

From a personal opinion, I wouldn't add a new dependency just for this. It's easier to just create a random string a-z0-9 of a fixed length and append the extension. I checked and the other library do not have any subdependencies, but in the end I think the filename inside the epub does not matter anyway.

@fmartingr fmartingr changed the title Fix: be sure filename is valid in any os fix: ensure automatically generated filename is a valid filename Feb 7, 2024
@Monirzadeh
Copy link
Author

Monirzadeh commented Feb 7, 2024

From a personal opinion, I wouldn't add a new dependency just for this. It's easier to just create a random string a-z0-9 of a fixed length and append the extension. I checked and the other library do not have any subdependencies, but in the end I think the filename inside the epub does not matter anyway.

the why i try to avoid to just create a random string is that lots of other part of the code (legacy part) use that filename (extension part) so it breaks lots of things.
i need to review that more carefully.
the invalid character is limited in any os what do you think if i done that as function inside go-epub for now?

@Monirzadeh
Copy link
Author

Monirzadeh commented Feb 10, 2024

@fmartingr some other place in code go-epub use github.com/gabriel-vasile/mimetype do you think we use that here instead of mime is better?

@fmartingr
Copy link
Member

@fmartingr some other place in code go-epub use github.com/gabriel-vasile/mimetype do you think we use that here instead of mime is better?

I didn't notice that dependency, was just doing some tests. If go-eupb already have it and it provides improvements over the standard library, yeah, absolutely.

@Monirzadeh
Copy link
Author

Monirzadeh commented Feb 11, 2024

@fmartingr some other place in code go-epub use github.com/gabriel-vasile/mimetype do you think we use that here instead of mime is better?

I didn't notice that dependency, was just doing some tests. If go-eupb already have it and it provides improvements over the standard library, yeah, absolutely.

I check that again, just because in the current solution we don't check the actual byte of the file (check only the header), it doesn't have any specific advantage.
If every things is ok. please approve this PR.

Copy link
Member

@fmartingr fmartingr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'd say this is a good compromise considering we are not downloading the files twice nor doing a big refactor in the code to guess the file type by its contents . 👍

@Monirzadeh Monirzadeh merged commit dc6435e into go-shiori:main Feb 11, 2024
4 checks passed
@Monirzadeh Monirzadeh deleted the fix-filename branch February 11, 2024 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

automatic file naming should clean filenames properly
3 participants