Repository navigation
fix(mime): GetExtType accepts an extension with or without the dot - #637
Draft
edsontmarques wants to merge 1 commit into
Draft
edsontmarques wants to merge 1 commit into
edsontmarques wants to merge 1 commit into
Conversation
GetExtType ran ExtractFileExt on the value it received. On FPC
ExtractFileExt('.css') is '' (a hidden file), and ExtractFileExt('css')
is '' on every compiler, so both came back as octet-stream and a static
.css served by extension broke in the browser. A value with no dot after
its first character is now read as an extension; anything else is a file
name. GetFileType always extracts the extension from the file name, so
its result does not change.
tests/fpc-mime fails on five extension cases against the previous source
and passes with the fix; it runs in the tests workflow.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and change
THorseMimeTypes.GetExtTypereturnsapplication/octet-streamfor an extension such as'.css'on FPC, and for an extension without the dot ('css') on every compiler that usesTHorseMimeTypesExt(FPC, and Delphi up to 10.2).THorseMimeTypesExt.NormalizeExtrunsExtractFileExton the value it receives:ExtractFileExt('.css')is'', because FPC reads.cssas a hidden file without extension;ExtractFileExt('css')is''everywhere.So a static file served by extension (for example, a caller passing
ExtractFileExt(FileName)) gets the wrong type, and the browser refuses the style sheet. Passing the whole file name works, which is why callers have been working around it.This patch reads a value with no dot after its first character as an extension (
'.css','css',' .CSS '). Anything else is a file name, and its extension comes fromExtractFileExtas before ('style.css','dir/x.min.js'). The value is trimmed and lower-cased first.GetFileTypenow always extracts the extension from the file name, so its result does not change for file names. A hidden file ('.css') and a name without extension ('pdf') still giveapplication/octet-stream.The
System.Net.Mimepath (Delphi 10.3 and later) is unchanged.Validation performed
FPC
3.3.1-22012-g6564bb9b34-unpushed, Linux x86_64.tests/fpc-mime: extensions with and without the dot, upper case, spaces, file names, hidden file, name without extension, unknown and empty41c4b1c(this PR's base).css,.js,css,.CSS,.CSStests.ymlReproduce from the repository root:
The script is registered in
.github/workflows/tests.yml, after the URL decoding regression.On our fork, an end-to-end check serves a static
.cssthrough Horse on FPC. It now answersContent-Type: text/css; before, it answeredapplication/octet-stream. Our Delphi 10.2 projects that use Horse also build without errors.Notes
jsontwice. The later entry,application/vnd.embarcadero.firedac+json, wins overapplication/json.vcfis also defined twice. This patch does not change the table: with it,GetExtType('.json')on FPC returns the same type thatGetFileType('x.json')already returned. That is left for a separate change.System.Net.Mimepath.🤖 Generated with Claude Code