hashid-rails 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 452d76b6a75d881163fd3f8a5216b458ac1d96fd
4
- data.tar.gz: 54201c5c82b115e15c207c7d0c57a8176cb490e7
3
+ metadata.gz: cf52f7660d6373fa40779618384e0ed119723ddb
4
+ data.tar.gz: 46ab38a8734c1c09a826bc39984bf8201c87a207
5
5
  SHA512:
6
- metadata.gz: b604b9ed6b7550f16445847d1f2f93de1af252cc70c1a72c76a2709cb803eda02598e8b0d2102705a109911dcc18f4abc916f025c293102da700303c24756233
7
- data.tar.gz: 679db7739b37d2d705e9b1745e78abd881682982c8d5fc591d6de159cc8641e3e2b10ace09e2084c0e7d3332eb2581747e810f72bb5208e697fc9cfb59ddf5f5
6
+ metadata.gz: 97335ce4d3e274f3dc57d70ecd08f70b851fb5a204051e6d63475b5125f0c045e701761db765b88e627e180eca74336dd013e9dc57afdcbbcd79befc69dce8c7
7
+ data.tar.gz: d58c2692ca18d302997a6ba1cb690187de52421cff9bbdfbb36687076b2ec8c9be3bc36498789a62bc963bb4a3c01735b06f08fc2672385f6dc797fe11e100ba
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.0 (2017-10-04)
4
+ - Add option to disable hashid signing. This adds backwards compatibility with
5
+ pre-1.0 releases. Thanks [@olliebennett](https://github.com/olliebennett)! ([#37](https://github.com/jcypret/hashid-rails/pull/37))
6
+ - Add note to README about upgrading from pre-1.0 releases.
7
+
3
8
  ## 1.0.0 (2017-04-29)
4
9
  - Sign hashids to prevent accidentally decoded regular ids
5
10
  - Require explicitly including Hashid::Rails in models
data/README.md CHANGED
@@ -10,6 +10,9 @@ will instead have unique short hashes like "yLA6m0oM", "5bAyD0LO", and
10
10
  "wz3MZ49l". The database will still use integers under the hood, so this gem can
11
11
  be added or removed at any time.
12
12
 
13
+ > IMPORTANT: If you need to maintain the same hashids from a pre-1.0 release,
14
+ > read the [upgrade notes](#upgrading-from-pre-10).
15
+
13
16
  ## Installation
14
17
 
15
18
  Add this line to your application's Gemfile:
@@ -110,9 +113,29 @@ Hashid::Rails.configure do |config|
110
113
 
111
114
  # Whether to override the `find` method
112
115
  config.override_find = true
116
+
117
+ # Whether to sign hashids to prevent conflicts with regular IDs (see https://github.com/jcypret/hashid-rails/issues/30)
118
+ config.sign_hashids = true
113
119
  end
114
120
  ```
115
121
 
122
+ ## Upgrading from Pre-1.0
123
+
124
+ The 1.0 release of this gem introduced hashid signing to prevent
125
+ conflicts with database IDs that could be mis-interpreted as hashids.
126
+ IDs are now signed when encoding and the signature verified when decoding.
127
+ The trade off is that hashids are different than in previous versions due to the added signature.
128
+ If you need to maintain the same hashids from a pre-1.0 version, set `sign_hashids` to false in the config.
129
+
130
+ Additionally, some of the config names have been modified to better match the parent [Hashid](https://github.com/peterhellberg/hashids.rb) project.
131
+ The config `secret` has been renamed to `salt` and the `length` renamed to `min_hash_length`.
132
+ Update the initializer config accordingly.
133
+
134
+ Lastly, `Hashid::Rails` is no longer imported into `ActiveRecord::Base` by default.
135
+ You can instead include `Hashid::Rails` selectively in the desired models,
136
+ or include it in `ApplicationRecord` for Rails 5 to apply to all subclassed models,
137
+ or add an initializer with `ActiveRecord::Base.send :include, Hashid::Rails` to match previous behavior.
138
+
116
139
  ## Development
117
140
 
118
141
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
@@ -78,13 +78,20 @@ module Hashid
78
78
  end
79
79
 
80
80
  def hashid_encode(id)
81
- hashids.encode(HASHID_TOKEN, id)
81
+ if Hashid::Rails.configuration.sign_hashids
82
+ hashids.encode(HASHID_TOKEN, id)
83
+ else
84
+ hashids.encode(id)
85
+ end
82
86
  end
83
87
 
84
88
  def hashid_decode(id)
85
89
  decoded_hashid = hashids.decode(id.to_s)
86
- return id unless valid_hashid?(decoded_hashid)
87
- decoded_hashid.last
90
+ if Hashid::Rails.configuration.sign_hashids
91
+ valid_hashid?(decoded_hashid) ? decoded_hashid.last : id
92
+ else
93
+ decoded_hashid.first
94
+ end
88
95
  end
89
96
 
90
97
  def valid_hashid?(decoded_hashid)
@@ -1,7 +1,11 @@
1
1
  module Hashid
2
2
  module Rails
3
3
  class Configuration
4
- attr_accessor :salt, :min_hash_length, :alphabet, :override_find
4
+ attr_accessor :salt,
5
+ :min_hash_length,
6
+ :alphabet,
7
+ :override_find,
8
+ :sign_hashids
5
9
 
6
10
  def initialize
7
11
  @salt = ""
@@ -10,6 +14,7 @@ module Hashid
10
14
  "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
11
15
  "1234567890"
12
16
  @override_find = true
17
+ @sign_hashids = true
13
18
  end
14
19
 
15
20
  def for_table(table_name)
@@ -1,5 +1,5 @@
1
1
  module Hashid
2
2
  module Rails
3
- VERSION = "1.0.0".freeze
3
+ VERSION = "1.1.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashid-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Cypret
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-29 00:00:00.000000000 Z
11
+ date: 2017-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler