Skip to content

Fix case sensitivity in KV.get #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ rvm:
- 2.7
script: bundle exec rake
env:
- RAILS_VERSION=6.0.3.1
- RAILS_VERSION=6.0.3.5
- RAILS_VERSION=5.2.0
services:
- mysql
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source "https://rubygems.org"
gemspec

DEFAULT_RAILS_VERSION = '6.0.3'
DEFAULT_RAILS_VERSION = '6.0.3.5'
ENV['RAILS_VERSION'] ||= DEFAULT_RAILS_VERSION

if ENV['RAILS_VERSION'] == '4.2.10'
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ pp kv.mdel(["foo", "bar"])
# nil
```

Note that due to MySQL's default collation, KV keys are case-insensitive.

### GitHub::SQL

```ruby
Expand Down
2 changes: 1 addition & 1 deletion lib/github/ds/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module GitHub
module DS
VERSION = "0.5.0"
VERSION = "0.5.1"
end
end
3 changes: 2 additions & 1 deletion lib/github/kv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def mget(keys)
SELECT `key`, value FROM #{@table_name} WHERE `key` IN :keys AND (`expires_at` IS NULL OR `expires_at` > :now)
SQL

keys.map { |key| kvs[key] }
kvs.keys.each { |key| kvs[key.downcase] = kvs[key] }
keys.map { |key| kvs[key.downcase] }
}
end

Expand Down
12 changes: 12 additions & 0 deletions test/github/kv_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ def test_mget_and_mset
assert_equal ["2", "1"], @kv.mget(["b", "a"]).value!
end

def test_get_and_set_case_insensitive
assert_nil @kv.get("foo").value!

@kv.set "foo", "lowercase"
assert_equal "lowercase", @kv.get("foo").value!
assert_equal "lowercase", @kv.get("FOO").value!

@kv.set "FOO", "uppercase"
assert_equal "uppercase", @kv.get("foo").value!
assert_equal "uppercase", @kv.get("FOO").value!
end

def test_get_failure
ActiveRecord::Base.connection.stubs(:select_all).raises(Errno::ECONNRESET)

Expand Down
4 changes: 2 additions & 2 deletions test/github/sql_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class GitHub::SQLTest < Minitest::Test
[DateTime.now.utc, "'1970-01-01 00:00:00'"],
[Time.now.utc, "'1970-01-01 00:00:00'"],
[Time.now.utc.to_date, "'1970-01-01'"],
[true, "1", {"5.2.0" => "TRUE", "6.0.3.1" => "TRUE"}],
[false, "0", {"5.2.0" => "FALSE", "6.0.3.1" => "FALSE"}],
[true, "1", {"5.2.0" => "TRUE", "6.0.3.5" => "TRUE"}],
[false, "0", {"5.2.0" => "FALSE", "6.0.3.5" => "FALSE"}],
[17, "17"],
[1.7, "1.7"],
["corge", "'corge'"],
Expand Down