Skip to content

Commit 4eede6b

Browse files
committed
Fix #249: leaking of options and internals in default serialization.
1 parent bca979c commit 4eede6b

File tree

6 files changed

+52
-16
lines changed

6 files changed

+52
-16
lines changed

.rubocop_todo.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,45 @@
1-
# This configuration was generated by `rubocop --auto-gen-config`
2-
# on 2015-08-10 13:14:22 +0300 using RuboCop version 0.31.0.
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config`
3+
# on 2016-11-20 10:04:42 -0500 using RuboCop version 0.45.0.
34
# The point is for the user to remove these configuration records
45
# one by one as the offenses are removed from the code base.
56
# Note that changes in the inspected code, or installation of new
67
# versions of RuboCop, may require this file to be generated again.
78

89
# Offense count: 6
910
Metrics/AbcSize:
10-
Max: 33
11+
Max: 32
1112

1213
# Offense count: 2
1314
# Configuration parameters: CountComments.
1415
Metrics/ClassLength:
15-
Max: 202
16+
Max: 206
1617

1718
# Offense count: 3
1819
Metrics/CyclomaticComplexity:
1920
Max: 11
2021

21-
# Offense count: 210
22-
# Configuration parameters: AllowURI, URISchemes.
22+
# Offense count: 237
23+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
24+
# URISchemes: http, https
2325
Metrics/LineLength:
2426
Max: 146
2527

26-
# Offense count: 8
28+
# Offense count: 6
2729
# Configuration parameters: CountComments.
2830
Metrics/MethodLength:
2931
Max: 28
3032

31-
# Offense count: 5
33+
# Offense count: 2
3234
Metrics/PerceivedComplexity:
3335
Max: 13
3436

35-
# Offense count: 58
37+
# Offense count: 33
3638
Style/Documentation:
3739
Enabled: false
3840

3941
# Offense count: 1
40-
# Configuration parameters: Exclude.
42+
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
4143
Style/FileName:
42-
Enabled: false
44+
Exclude:
45+
- 'lib/grape-entity.rb'

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### Next
1+
### 0.6.0 (Next)
22

33
#### Features
44

@@ -7,6 +7,7 @@
77

88
#### Fixes
99

10+
* [#249](https://github.com/ruby-grape/grape-entity/issues/249): Fix leaking of options and internals in default serialization - [@dblock](https://github.com/dblock), [@KingsleyKelly](https://github.com/KingsleyKelly).
1011
* [#248](https://github.com/ruby-grape/grape-entity/pull/248): Fix `nil` values causing errors when `merge` option passed - [@arempe93](https://github.com/arempe93).
1112
* Your contribution here.
1213

UPGRADING.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
Upgrading Grape Entity
22
===============
33

4+
### Upgrading to >= 0.6.0
5+
6+
#### Changes in Grape::Entity#inspect
7+
8+
The `Grape::Entity#inspect` method will no longer serialize the entity presenter with its options and delegator, but the exposed entity itself, using `#serializable_hash`.
9+
10+
See [#250](https://github.com/ruby-grape/grape-entity/pull/250) for more information.
11+
412
### Upgrading to >= 0.5.1
513

6-
* `Grape::Entity::Exposure::NestingExposure::NestedExposures.delete_if` always
7-
returns exposures, regardless of delete result (used to be
8-
`nil` in negative case), see [#203](https://github.com/ruby-grape/grape-entity/pull/203).
14+
#### Changes in NestedExposures.delete_if
15+
16+
`Grape::Entity::Exposure::NestingExposure::NestedExposures.delete_if` always returns exposures, regardless of delete result (used to be `nil` in negative case).
17+
18+
See [#203](https://github.com/ruby-grape/grape-entity/pull/203) for more information.

lib/grape_entity/entity.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,12 @@ def presented
424424
end
425425
end
426426

427+
# Prevent default serialization of :options or :delegator.
428+
def inspect
429+
fields = serializable_hash.map { |k, v| "#{k}=#{v}" }
430+
"#<#{self.class.name}:#{object_id} #{fields.join(' ')}>"
431+
end
432+
427433
def initialize(object, options = {})
428434
@object = object
429435
@delegator = Delegator.new object

lib/grape_entity/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module GrapeEntity
2-
VERSION = '0.5.2'.freeze
2+
VERSION = '0.6.0'.freeze
33
end

spec/grape_entity/entity_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,22 @@ class NoPathCharacterEntity < Grape::Entity
13471347
end
13481348
end
13491349

1350+
describe '#inspect' do
1351+
before do
1352+
fresh_class.class_eval do
1353+
expose :name, :email
1354+
end
1355+
end
1356+
1357+
it 'does not serialize delegator or options' do
1358+
data = subject.inspect
1359+
expect(data).to include 'name='
1360+
expect(data).to include 'email='
1361+
expect(data).to_not include '@options'
1362+
expect(data).to_not include '@delegator'
1363+
end
1364+
end
1365+
13501366
describe '#value_for' do
13511367
before do
13521368
fresh_class.class_eval do

0 commit comments

Comments
 (0)