Skip to content

Commit dbe35de

Browse files
authored
Fix improper handling of optional file uploads (athena-framework/athena#595)
* Bump `framework` component
1 parent bb45894 commit dbe35de

5 files changed

Lines changed: 28 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## [0.21.1] - 2025-10-04
4+
5+
### Fixed
6+
7+
- Fix improper handling of optional file uploads ([#595]) (George Dietrich) <!-- blacksmoke16 -->
8+
9+
[0.21.1]: https://github.com/athena-framework/framework/releases/tag/v0.21.1
10+
[#595]: https://github.com/athena-framework/athena/pull/595
11+
312
## [0.21.0] - 2025-09-04
413

514
### Changed

shard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: athena
22

3-
version: 0.21.0
3+
version: 0.21.1
44

55
crystal: ~> 1.14
66

spec/file_parser_spec.cr

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ struct FileParserTest < ASPEC::TestCase
88
request = new_request(
99
body: String.build do |io|
1010
HTTP::FormData.build io, "boundary" do |form|
11+
# Non HTML file input types have a `nil` filename.
1112
form.field("age", 12)
1213
form.file(
1314
"success",
@@ -20,6 +21,18 @@ struct FileParserTest < ASPEC::TestCase
2021
}
2122
)
2223

24+
# Skipped because optional HTML file input types have a `""` filename if no file was selected.
25+
form.file(
26+
"optional",
27+
IO::Memory.new,
28+
HTTP::FormData::FileMetadata.new(
29+
""
30+
),
31+
headers: HTTP::Headers{
32+
"content-type" => "text/plain",
33+
}
34+
)
35+
2336
form.file(
2437
"too_big",
2538
File.open("#{__DIR__}/assets/file-big.txt"),
@@ -75,6 +88,7 @@ struct FileParserTest < ASPEC::TestCase
7588
file_parser.uploaded_file?(file2.path).should be_false
7689

7790
request.attributes.get("age", String).should eq "12"
91+
request.attributes.has?("optional").should be_false
7892

7993
file_parser.clear
8094

src/athena.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ alias ATHA = ATH::Annotations
6262
alias ATHR = ATH::Controller::ValueResolvers
6363

6464
module Athena::Framework
65-
VERSION = "0.21.0"
65+
VERSION = "0.21.1"
6666

6767
# The name of the environment variable used to determine Athena's current environment.
6868
ENV_NAME = "ATHENA_ENV"

src/file_parser.cr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ class Athena::Framework::FileParser
2121
uploaded_file_count = 0
2222

2323
HTTP::FormData.parse(request.request) do |part|
24-
unless filename = part.filename.presence
24+
case filename = part.filename
25+
when "" then next
26+
when .nil?
2527
request.attributes.set part.name, part.body.gets_to_end, String
2628
next
2729
end

0 commit comments

Comments
 (0)