hashids 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f35febe06ea136b13641845c57ec208d60aa40e
4
- data.tar.gz: 23757c01a68fd1effa709a40e2aebfd6825a126d
3
+ metadata.gz: 78ce10327504b42999d641f7f5e1c1783cf20208
4
+ data.tar.gz: 72dde477590fe6e4618cfa38d21a17a7923ca5ad
5
5
  SHA512:
6
- metadata.gz: 15be6da0e98af26bc7506526820fe5b37b481c9be9b13c05bf52b67632c6554c4bb350f93d6f262edc554808c5b664544cebc60497970cfb3b44a191af7e1be6
7
- data.tar.gz: 873982fd791ff1fe6a8166ff956cb2249d23c87136df69e3a928b0959c6badd820873c2ceab6a8a66226ef618aa854c9366a465662dfb10676db362407e6ac2c
6
+ metadata.gz: fb41de55bd4c95a0ec76ad8f851f85aaaff6a710a822c46e50f8453e5f70927fa7c8aaf221cc41d7c493907542fd48e8359bb0ceec47a1e5e026b9c2d53ead3f
7
+ data.tar.gz: 5cc3fe49ce4849d4e720f83c9d09ef0ad984610187a1ab1db549d55351c247d79e3e3c238e1a537187842b46e39b793b03c1b4eaad1efa84cfd9197a98c03b19
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  class Hashids
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.2"
5
5
 
6
6
  MIN_ALPHABET_LENGTH = 16
7
7
  SEP_DIV = 3.5
@@ -180,6 +180,9 @@ class Hashids
180
180
 
181
181
  input.length.times do |i|
182
182
  pos = alphabet.index(input[i])
183
+
184
+ raise InputError, "unable to unhash" unless pos
185
+
183
186
  num += pos * alphabet.length ** (input.length - i - 1)
184
187
  end
185
188
 
@@ -249,6 +252,7 @@ class Hashids
249
252
  SaltError = Class.new(ArgumentError)
250
253
  MinLengthError = Class.new(ArgumentError)
251
254
  AlphabetError = Class.new(ArgumentError)
255
+ InputError = Class.new(ArgumentError)
252
256
 
253
257
  def validate_attributes
254
258
  unless salt.kind_of?(String)
@@ -214,6 +214,10 @@ describe Hashids do
214
214
  h.decode("mxi8XH87").must_equal [25, 100, 950]
215
215
  h.decode("KQcmkIW8hX").must_equal [5,200,195, 1]
216
216
  end
217
+
218
+ it "handles invalid input by raising InputError" do
219
+ -> { hashids.decode('asdf-') }.must_raise Hashids::InputError
220
+ end
217
221
  end
218
222
 
219
223
  describe "decode_hex" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashids
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Hellberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-23 00:00:00.000000000 Z
11
+ date: 2014-12-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Use hashids when you do not want to expose your database ids to the user.
14
14
  email:
@@ -45,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
45
  version: '0'
46
46
  requirements: []
47
47
  rubyforge_project:
48
- rubygems_version: 2.2.2
48
+ rubygems_version: 2.4.3
49
49
  signing_key:
50
50
  specification_version: 4
51
51
  summary: Generate YouTube-like hashes from one or many numbers.