Skip to content

Commit

Permalink
fix: spec update (PR #7) - blocklist filtering in uppercase-only alph…
Browse files Browse the repository at this point in the history
…abet
  • Loading branch information
4kimov committed Aug 30, 2023
1 parent acb0224 commit 59ad779
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

**v0.1.2:**
- Bug fix: spec update (PR #7): blocklist filtering in uppercase-only alphabet [[PR #7](https://github.com/sqids/sqids-spec/pull/7)]
- Lower uniques test from 1_000_000 to 10_000

**v0.1.1:**
- Lowering Ruby version requirement to 3.0

Expand Down
2 changes: 1 addition & 1 deletion lib/sqids.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def initialize(options = {})
end

filtered_blocklist = blocklist.select do |word|
word.length >= 3 && (word.chars - alphabet.chars).empty?
word.length >= 3 && (word.downcase.chars - alphabet.downcase.chars).empty?
end.to_set(&:downcase)

@alphabet = shuffle(alphabet)
Expand Down
11 changes: 11 additions & 0 deletions spec/blocklist_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,15 @@

expect(sqids.decode(sqids.encode([1_000]))).to eq([1_000])
end

it 'blocklist filtering in constructor' do
# lowercase blocklist in only-uppercase alphabet
sqids = Sqids.new(alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', blocklist: Set.new(['sqnmpn']))

id = sqids.encode([1, 2, 3])
numbers = sqids.decode(id)

expect(id).to eq('ULPBZGBM') # without blocklist, would've been "SQNMPN"
expect(numbers).to eq([1, 2, 3])
end
end
2 changes: 1 addition & 1 deletion spec/uniques_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'rspec'
require_relative '../lib/sqids'

upper = 1_000_000
upper = 10_000

describe Sqids do
let(:sqids) { Sqids.new(min_length: Sqids::DEFAULT_ALPHABET.length) }
Expand Down
2 changes: 1 addition & 1 deletion sqids.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require 'sqids'

Gem::Specification.new do |gem|
gem.name = 'sqids'
gem.version = '0.1.1'
gem.version = '0.1.2'
gem.authors = ['Sqids Maintainers']
gem.summary = 'Generate YouTube-like ids from numbers.'
gem.homepage = 'https://sqids.org/ruby'
Expand Down

0 comments on commit 59ad779

Please sign in to comment.