hashids 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hashids.rb +5 -1
- data/spec/hashids_spec.rb +4 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78ce10327504b42999d641f7f5e1c1783cf20208
|
4
|
+
data.tar.gz: 72dde477590fe6e4618cfa38d21a17a7923ca5ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb41de55bd4c95a0ec76ad8f851f85aaaff6a710a822c46e50f8453e5f70927fa7c8aaf221cc41d7c493907542fd48e8359bb0ceec47a1e5e026b9c2d53ead3f
|
7
|
+
data.tar.gz: 5cc3fe49ce4849d4e720f83c9d09ef0ad984610187a1ab1db549d55351c247d79e3e3c238e1a537187842b46e39b793b03c1b4eaad1efa84cfd9197a98c03b19
|
data/lib/hashids.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
class Hashids
|
4
|
-
VERSION = "1.0.
|
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)
|
data/spec/hashids_spec.rb
CHANGED
@@ -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.
|
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-
|
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.
|
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.
|