rollbar 0.13.2 → 1.0.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: b3f1bfea5b0039c34e065755ca4d589cfc5756b8
4
- data.tar.gz: 2ccff055b8ca9a5e3d5e95f5ba57874de697acc8
3
+ metadata.gz: 3f2c782eb71538b4fa602e2e56c56233559858f7
4
+ data.tar.gz: 6ad6c0a6b66963dc0b0a2bdb0705df9d95e4f468
5
5
  SHA512:
6
- metadata.gz: f6e7fdacbe2ca39f560f4d616a6282413b6d170c8b8aaeca4f616725d84be8beaf55e2318c994aebf1b74028c42824401da745645c553c2671f60867b37be4d0
7
- data.tar.gz: a3ba21e9df754a5f47381a5f83f6aa90e4554ab4720af6e543e15d6124450600825f64e9e0271f2c08e6cf87edc9262373aa88e173a3c8b739ad7247526f58df
6
+ metadata.gz: fddd828f6ff42f93a0211e4967baf4a99ff1c93f1b5c1ee1a231004627b80c5b18dfbf6684d94a141144e29bebd17e5d9e6d977844506fb62cd7524272e29ebe
7
+ data.tar.gz: f6820508de41ddc3fcb9ff89bab83da096a6b778d97bdca10297982561f139d6f1c7591d120bb9165a3bcc3601d7ca5f17c89a137cb49f114b00c8c01273f77c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change Log
2
2
 
3
+ **1.0.0**
4
+ - Clean up some unused requires
5
+ - Strip out invalid UTF-8 characters from payload keys/values, fixes [#85](https://github.com/rollbar/rollbar-gem/issues/85)
6
+ - Bumping to 1.0 due to the suggestion in [#119](https://github.com/rollbar/rollbar-gem/issues/119)
7
+
3
8
  **0.13.2**
4
9
  - Sidekiq payload is no longer mutated when Rollbar reports a Sidekiq job exception
5
10
  - Fix sucker_punch async reporting when using a forking application server such as Unicorn (`preload_app true`). Jobs are now instantiated for every report instead of a reused global job instance
data/lib/rollbar.rb CHANGED
@@ -1,23 +1,26 @@
1
1
  require 'net/https'
2
-
3
- require 'securerandom' if defined?(SecureRandom)
4
2
  require 'socket'
5
3
  require 'thread'
6
4
  require 'uri'
7
-
8
- require 'girl_friday' if defined?(GirlFriday)
9
- require 'sucker_punch' if defined?(SuckerPunch)
10
5
  require 'multi_json'
11
6
 
7
+ begin
8
+ require 'securerandom'
9
+ rescue LoadError
10
+ end
11
+
12
12
  require 'rollbar/version'
13
13
  require 'rollbar/configuration'
14
14
  require 'rollbar/request_data_extractor'
15
15
  require 'rollbar/exception_reporter'
16
16
  require 'rollbar/active_record_extension' if defined?(ActiveRecord)
17
17
  require 'rollbar/util'
18
-
19
18
  require 'rollbar/railtie' if defined?(Rails)
20
19
 
20
+ unless ''.respond_to? :encode
21
+ require 'iconv'
22
+ end
23
+
21
24
  module Rollbar
22
25
  MAX_PAYLOAD_SIZE = 128 * 1024 #128kb
23
26
 
@@ -30,7 +33,7 @@ module Rollbar
30
33
  def preconfigure
31
34
  yield(configuration)
32
35
  end
33
-
36
+
34
37
  # Configures the gem.
35
38
  #
36
39
  # Call on app startup to set the `access_token` (required) and other config params.
@@ -47,7 +50,7 @@ module Rollbar
47
50
  configuration.enabled = true
48
51
  end
49
52
  yield(configuration)
50
-
53
+
51
54
  require_hooks
52
55
  end
53
56
 
@@ -252,7 +255,7 @@ module Rollbar
252
255
  require 'rollbar/delayed_job'
253
256
  Rollbar::Delayed::wrap_worker
254
257
  end
255
-
258
+
256
259
  require 'rollbar/sidekiq' if defined?(Sidekiq)
257
260
  require 'rollbar/goalie' if defined?(Goalie)
258
261
  require 'rollbar/rack' if defined?(Rack)
@@ -444,6 +447,9 @@ module Rollbar
444
447
  :access_token => configuration.access_token,
445
448
  :data => data
446
449
  }
450
+
451
+ enforce_valid_utf8(payload)
452
+
447
453
  result = MultiJson.dump(payload)
448
454
 
449
455
  # Try to truncate strings in the payload a few times if the payload is too big
@@ -602,6 +608,22 @@ module Rollbar
602
608
  log_error "[Rollbar] Error sending failsafe : #{e}"
603
609
  end
604
610
  end
611
+
612
+ def enforce_valid_utf8(payload)
613
+ normalizer = Proc.new do |value|
614
+ if value.is_a?(String)
615
+ if value.respond_to? :encode
616
+ value.encode('UTF-8', 'binary', :invalid => :replace, :undef => :replace, :replace => '')
617
+ else
618
+ ::Iconv.conv('UTF-8//IGNORE', 'UTF-8', value)
619
+ end
620
+ else
621
+ value
622
+ end
623
+ end
624
+
625
+ Rollbar::Util::iterate_and_update(payload, normalizer)
626
+ end
605
627
 
606
628
  def truncate_payload(payload, byte_threshold)
607
629
  truncator = Proc.new do |value|
@@ -1,4 +1,4 @@
1
- require 'rails'
1
+ require 'rails/railtie'
2
2
  require 'rollbar'
3
3
 
4
4
  module Rollbar
@@ -6,7 +6,7 @@ module Rollbar
6
6
  rake_tasks do
7
7
  require 'rollbar/rake_tasks'
8
8
  end
9
-
9
+
10
10
  if defined? ActiveRecord
11
11
  initializer 'rollbar.middleware.rails' do |app|
12
12
  require 'rollbar/middleware/rails/rollbar_request_store'
data/lib/rollbar/util.rb CHANGED
@@ -12,12 +12,27 @@ module Rollbar
12
12
  end
13
13
  end
14
14
  else
15
+ key_updates = []
16
+
15
17
  obj.each do |k, v|
18
+ new_key = nil
19
+
16
20
  if v.is_a?(Hash) || v.is_a?(Array)
17
21
  self.iterate_and_update(v, block)
22
+ new_key = block.call(k)
18
23
  else
24
+ new_key = block.call(k)
19
25
  obj[k] = block.call(v)
20
26
  end
27
+
28
+ if new_key != k
29
+ key_updates.push([k, new_key])
30
+ end
31
+ end
32
+
33
+ key_updates.each do |old_key, new_key|
34
+ obj[new_key] = obj[old_key]
35
+ obj.delete(old_key)
21
36
  end
22
37
  end
23
38
  end
@@ -32,4 +47,4 @@ module Rollbar
32
47
  str.unpack("U*").slice(0, length - ellipsis.length).pack("U*") + ellipsis
33
48
  end
34
49
  end
35
- end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module Rollbar
2
- VERSION = "0.13.2"
2
+ VERSION = "1.0.0"
3
3
  end
data/spec/rollbar_spec.rb CHANGED
@@ -666,6 +666,25 @@ describe Rollbar do
666
666
  hash = MultiJson.load(json)
667
667
  hash["data"]["foo"]["bar"].should == "baz"
668
668
  end
669
+
670
+ it 'should strip out invalid utf-8' do
671
+ json = Rollbar.send(:build_payload, {
672
+ :good_key => "\255bad value",
673
+ "bad\255 key" => "good value",
674
+ "bad key 2\255" => "bad \255value",
675
+ :hash => {
676
+ "bad array \255key" => ["bad\255 array element", "good array element"]
677
+ }
678
+ })
679
+
680
+ hash = MultiJson.load(json)
681
+ hash["data"]["good_key"].should == 'bad value'
682
+ hash["data"]["bad key"].should == 'good value'
683
+ hash["data"]["bad key 2"].should == 'bad value'
684
+ hash["data"]["hash"].should == {
685
+ "bad array key" => ["bad array element", "good array element"]
686
+ }
687
+ end
669
688
 
670
689
  it 'should truncate large strings if the payload is too big' do
671
690
  json = Rollbar.send(:build_payload, {:foo => {:bar => "baz"}, :large => 'a' * (128 * 1024), :small => 'b' * 1024})
@@ -686,6 +705,44 @@ describe Rollbar do
686
705
  Rollbar::MAX_PAYLOAD_SIZE = orig_max
687
706
  end
688
707
  end
708
+
709
+ context 'enforce_valid_utf8' do
710
+ it 'should replace invalid utf8 values' do
711
+ payload = {
712
+ :bad_value => "bad value 1\255",
713
+ :bad_value_2 => "bad\255 value 2",
714
+ "bad\255 key" => "good value",
715
+ :hash => {
716
+ :inner_bad_value => "\255\255bad value 3",
717
+ "inner \255bad key" => 'inner good value',
718
+ "bad array key\255" => [
719
+ 'good array value 1',
720
+ "bad\255 array value 1\255",
721
+ {
722
+ :inner_inner_bad => "bad inner \255inner value"
723
+ }
724
+ ]
725
+ }
726
+ }
727
+
728
+ payload_copy = payload.clone
729
+ Rollbar.send(:enforce_valid_utf8, payload_copy)
730
+
731
+ payload_copy[:bad_value].should == "bad value 1"
732
+ payload_copy[:bad_value_2].should == "bad value 2"
733
+ payload_copy["bad key"].should == "good value"
734
+ payload_copy.keys.should_not include("bad\456 key")
735
+ payload_copy[:hash][:inner_bad_value].should == "bad value 3"
736
+ payload_copy[:hash]["inner bad key"].should == 'inner good value'
737
+ payload_copy[:hash]["bad array key"].should == [
738
+ 'good array value 1',
739
+ 'bad array value 1',
740
+ {
741
+ :inner_inner_bad => 'bad inner inner value'
742
+ }
743
+ ]
744
+ end
745
+ end
689
746
 
690
747
  context 'truncate_payload' do
691
748
  it 'should truncate all nested strings in the payload' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rollbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Rue
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-09 00:00:00.000000000 Z
11
+ date: 2014-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json