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: 49f52ea1e3ab
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: e637f567784e
Choose a head ref
  • 4 commits
  • 6 files changed
  • 1 contributor

Commits on Dec 3, 2016

  1. Rename Set#merge to Set#merge!. Fixes #3625

    Ary Borenszweig committed Dec 3, 2016
    Copy the full SHA
    b8894e5 View commit details
  2. Set: use backticks in code examples, so the formatter is used. Also f…

    …avor Set{...} instead of Set.new([...]).
    Ary Borenszweig committed Dec 3, 2016
    Copy the full SHA
    50dd1fd View commit details
  3. Copy the full SHA
    fda7873 View commit details
  4. Copy the full SHA
    e637f56 View commit details
Showing with 163 additions and 82 deletions.
  1. +18 −0 spec/std/http/headers_spec.cr
  2. +2 −2 spec/std/set_spec.cr
  3. +1 −1 src/compiler/crystal/compiler.cr
  4. +15 −6 src/http/headers.cr
  5. +118 −70 src/set.cr
  6. +9 −3 src/slice.cr
18 changes: 18 additions & 0 deletions spec/std/http/headers_spec.cr
Original file line number Diff line number Diff line change
@@ -147,6 +147,24 @@ describe HTTP::Headers do
headers.includes_word?("foo", "ba").should be_false
end

it "matches word with comma separated value, case insensitive (#3626)" do
headers = HTTP::Headers{"foo" => "BaR, BAZ"}
headers.includes_word?("foo", "bar").should be_true
headers.includes_word?("foo", "baz").should be_true
headers.includes_word?("foo", "BAR").should be_true
headers.includes_word?("foo", "ba").should be_false
end

it "doesn't match empty string" do
headers = HTTP::Headers{"foo" => "bar, baz"}
headers.includes_word?("foo", "").should be_false
end

it "matches word with comma separated value, partial match" do
headers = HTTP::Headers{"foo" => "bar, bazo, baz"}
headers.includes_word?("foo", "baz").should be_true
end

it "matches word among headers" do
headers = HTTP::Headers.new
headers.add("foo", "bar")
4 changes: 2 additions & 2 deletions spec/std/set_spec.cr
Original file line number Diff line number Diff line change
@@ -104,13 +104,13 @@ describe "Set" do
describe "merge" do
it "adds all the other elements" do
set = Set{1, 4, 8}
set.merge [1, 9, 10]
set.merge! [1, 9, 10]
set.should eq(Set{1, 4, 8, 9, 10})
end

it "returns self" do
set = Set{1, 4, 8}
set.merge([1, 9, 10]).should eq(Set{1, 4, 8, 9, 10})
set.merge!([1, 9, 10]).should eq(Set{1, 4, 8, 9, 10})
end
end

2 changes: 1 addition & 1 deletion src/compiler/crystal/compiler.cr
Original file line number Diff line number Diff line change
@@ -152,7 +152,7 @@ module Crystal
program.cache_dir = CacheDir.instance.directory_for(sources)
program.target_machine = target_machine
program.flags << "release" if @release
program.flags.merge @flags
program.flags.merge! @flags
program.wants_doc = wants_doc?
program.color = color?
program.stdout = stdout
21 changes: 15 additions & 6 deletions src/http/headers.cr
Original file line number Diff line number Diff line change
@@ -79,14 +79,23 @@ struct HTTP::Headers
# headers.includes_word?("Connection", "Upgrade") # => true
# ```
def includes_word?(key, word)
return false if word.empty?

word = word.downcase
# iterates over all header values avoiding the concatenation
get?(key).try &.each do |value|
start = value.index(word)
next unless start
# check if the match is not surrounded by alphanumeric chars
next if start > 0 && value[start - 1].ascii_alphanumeric?
next if start + word.size < value.size && value[start + word.size].alphanumeric?
return true
value = value.downcase
offset = 0
while true
start = value.index(word, offset)
break unless start
offset = start + word.size

# check if the match is not surrounded by alphanumeric chars
next if start > 0 && value[start - 1].ascii_alphanumeric?
next if start + word.size < value.size && value[start + word.size].ascii_alphanumeric?
return true
end
end

false
Loading