Skip to content

astextplain: use mimetype to decide helper #624

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

Merged

Conversation

rimrul
Copy link
Member

@rimrul rimrul commented Jun 7, 2025

We use the file extension to determine which helper to call to convert a file to text. We currently match an all upper case version and an all lower case version of each extension, but sometimes variations like 'foo.Rtf' fall though our raster.

To cover all variations in this established way we'd have to add every permutation of upper and lower case for each extension to the script. That's a big maintainance burden.
We could also convert the passed filename to a known case and match against that. Since POSIX has no easy way for sh to do case conversion in-process we'd have to shell out to tr, awk or similar.

For the antiword helper we already need to make sure the file is of the type it claims by it's extension. We use file to tell us the mimetype for this. file can also tell us the types of other files we care about for astextplain, so we can use it for the decision which helper to use in the first place.

This fixes git-for-windows/git#5641

@rimrul rimrul force-pushed the astextplain-casesensitive-extensions-fix branch from c72c8a9 to 2a05a0d Compare June 7, 2025 08:30
We use the file extension to determine which helper to call to convert a
file to text. We currently match an all upper case version and an all
lower case version of each extension, but sometimes variations like
'foo.Rtf' fall though our raster.

To cover all variations in this established way we'd have to add every
permutation of upper and lower case for each extension to the script.
That's a big maintainance burden.
We could also convert the passed filename to a known case and match
against that. Since POSIX has no easy way for sh to do case conversion
in-process we'd have to shell out to tr, awk or similar.

For the antiword helper we already need to make sure the file is of the
type it claims by it's extension. We use file to tell us the mimetype
for this. file can also tell us the types of other files we care about
for astextplain, so we can use it for the decision which helper to use
in the first place.

This fixes git-for-windows/git#5641

Signed-off-by: Matthias Aßhauer <mha1993@live.de>
@rimrul rimrul force-pushed the astextplain-casesensitive-extensions-fix branch from 2a05a0d to e3eddae Compare June 7, 2025 09:12
@rimrul rimrul marked this pull request as ready for review June 7, 2025 09:21
@dscho
Copy link
Member

dscho commented Jun 9, 2025

/deploy git-extra

The i686/x86_64 and the arm64 workflow runs were started.

@dscho
Copy link
Member

dscho commented Jun 9, 2025

/updpkgsums

The workflow run was started.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho
Copy link
Member

dscho commented Jun 9, 2025

/deploy git-extra

The i686/x86_64 and the arm64 workflow runs were started.

@dscho dscho merged commit dcf30e3 into git-for-windows:main Jun 9, 2025
9 checks passed
@rimrul rimrul deleted the astextplain-casesensitive-extensions-fix branch June 9, 2025 09:17
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.

diff=astextplain "unsupported filetype" error on mixed-case extension
2 participants