Skip to content

Commit

Permalink
Merge pull request #615 from JuliaWeb/cdg/form-boundary
Browse files Browse the repository at this point in the history
Add verification of the boundary
  • Loading branch information
quinnj committed Nov 2, 2020
2 parents b4a37aa + bf521d7 commit 7d03dc1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/multipart.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ function Base.read(f::Form, n::Integer)
end

function Form(d; boundary=string(rand(UInt128), base=16))
# https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
bcharsnospace = raw"\w'\(\)\+,-\./:=\?"
boundary_re = Regex("^[$bcharsnospace ]{0,69}[$bcharsnospace]\$")
@require match(boundary_re, boundary) !== nothing
@require eltype(d) <: Pair
data = IO[]
io = IOBuffer()
Expand Down
10 changes: 10 additions & 0 deletions test/multipart.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,14 @@
@test_nowarn HTTP.Multipart(nothing, IOBuffer("some data"), "plain/text", "", "testname")
@test_throws MethodError HTTP.Multipart(nothing, "some data", "plain/text", "", "testname")
end

@testset "Boundary" begin
@test HTTP.Form(Dict()) isa HTTP.Form
@test HTTP.Form(Dict(); boundary="a") isa HTTP.Form
@test HTTP.Form(Dict(); boundary=" Aa1'()+,-.:=?") isa HTTP.Form
@test HTTP.Form(Dict(); boundary='a'^70) isa HTTP.Form
@test_throws ArgumentError HTTP.Form(Dict(); boundary="")
@test_throws ArgumentError HTTP.Form(Dict(); boundary='a'^71)
@test_throws ArgumentError HTTP.Form(Dict(); boundary="a ")
end
end

0 comments on commit 7d03dc1

Please sign in to comment.