Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9ba6ba93e3cd
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0990ca130764
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Jul 7, 2018

  1. Copy the full SHA
    d2a9b43 View commit details

Commits on Jul 9, 2018

  1. Merge pull request #6354 from asterite/bug/6353-quoted-charset

    HTTP: consider quoted charset
    ysbaddaden authored Jul 9, 2018
    Copy the full SHA
    0990ca1 View commit details
Showing with 12 additions and 0 deletions.
  1. +6 −0 spec/std/http/client/response_spec.cr
  2. +6 −0 src/http/common.cr
6 changes: 6 additions & 0 deletions spec/std/http/client/response_spec.cr
Original file line number Diff line number Diff line change
@@ -266,6 +266,12 @@ class HTTP::Client
response.charset.should eq("UTF-8")
end

it "returns content type and charset, removes quotes" do
response = Response.new(200, "", headers: HTTP::Headers{"Content-Type" => %(text/plain ; charset="UTF-8")})
response.content_type.should eq("text/plain")
response.charset.should eq("UTF-8")
end

it "returns content type and no charset, other parameter (#2520)" do
response = Response.new(200, "", headers: HTTP::Headers{"Content-Type" => "text/plain ; colenc=U"})
response.content_type.should eq("text/plain")
6 changes: 6 additions & 0 deletions src/http/common.cr
Original file line number Diff line number Diff line change
@@ -214,6 +214,12 @@ module HTTP
key = piece[0...eq_index].strip
if key == "charset"
value = piece[eq_index + 1..-1].strip

# For the case of a quoted charset like charset="utf-8"
if value.starts_with?('"') && value.ends_with?('"')
value = value[1...-1].strip
end

return ComputedContentTypeHeader.new(content_type, value)
end
end