bullet 8.0.3 → 8.0.4

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
  SHA256:
3
- metadata.gz: 0b32cc08a4de57560f18996d4ff4c96cb7a8cbc36cfb6dc285f612ac8ccd8f2e
4
- data.tar.gz: 1d5b9e6f885039b6a3208d546b2ebad0a44e8063c4e1fffc7d74790ba79c1f71
3
+ metadata.gz: a61908a92c8bc22bba69f9ea56946f1b6b2abd320e392e7539a3a6024b939b0c
4
+ data.tar.gz: 1fc844bc72f0e9e4c046590ef3f981180ce0beb5e32fab2217592d21e3456705
5
5
  SHA512:
6
- metadata.gz: fb317b0bab9154eb40be0a315f1fe767ff8c227f631ee6b25e270c31422fb6aa7b4857ae7cb33b9155eb8a2300a1c52d6097fef899ad02b7cae42c8c7082e2a6
7
- data.tar.gz: ba13a423de83f43a6a5a2d75a576e4612011c21cf835f2204cda2b02114680f03cf397b7d28f476eefd1c8e933da2a7e0ab9e860ee28f9e0dbbb1ecbf5abeef7
6
+ metadata.gz: 456c8c81a574243cda8ad3a3bb728b0ae97f169434e1608158a72967b8f9a6e7153939fcb2ce7c9d9e363921e918871e6a8b3ed7c374a45bc910170a4cb3e779
7
+ data.tar.gz: 3ebfc6724a13326f9d2286506727edb5d47b66b01253fbc48a2407d9e7f1c6c3f8ac700d7405024fcc86766a9fd65d170d0eea0678ffd1af3c60dd90b0c82b06
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## Next Release
2
2
 
3
+ ## 8.0.4 (04/18/2024)
4
+
5
+ * Insert bullet middleware before `ContentSecurityPolicy`
6
+ * Support url query `skip_html_injection=true`
7
+ * Mark object as impossible after updating inversed
8
+
3
9
  ## 8.0.3 (04/04/2025)
4
10
 
5
11
  * Update non persisted `inversed_objects`
data/README.md CHANGED
@@ -192,6 +192,11 @@ see [https://github.com/flyerhzm/uniform_notifier](https://github.com/flyerhzm/u
192
192
 
193
193
  Growl support is dropped from uniform_notifier 1.16.0, if you still want it, please use uniform_notifier 1.15.0.
194
194
 
195
+ ## URL query control
196
+
197
+ You can add the URL query parameter `skip_html_injection` to make the current HTML request behave as if `Bullet.skip_html_injection` is enabled,
198
+ e.g. `http://localhost:3000/posts?skip_html_injection=true`
199
+
195
200
  ## Important
196
201
 
197
202
  If you find Bullet does not work for you, *please disable your browser's cache*.
@@ -49,7 +49,10 @@ module Bullet
49
49
 
50
50
  ::ActiveRecord::Persistence.class_eval do
51
51
  def _create_record_with_bullet(*args)
52
- _create_record_without_bullet(*args).tap { Bullet::Detector::NPlusOneQuery.update_inversed_object(self) }
52
+ _create_record_without_bullet(*args).tap do
53
+ Bullet::Detector::NPlusOneQuery.update_inversed_object(self)
54
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
55
+ end
53
56
  end
54
57
  alias_method_chain :_create_record, :bullet
55
58
  end
@@ -52,7 +52,10 @@ module Bullet
52
52
 
53
53
  ::ActiveRecord::Persistence.class_eval do
54
54
  def _create_record_with_bullet(*args)
55
- _create_record_without_bullet(*args).tap { Bullet::Detector::NPlusOneQuery.update_inversed_object(self) }
55
+ _create_record_without_bullet(*args).tap do
56
+ Bullet::Detector::NPlusOneQuery.update_inversed_object(self)
57
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
58
+ end
56
59
  end
57
60
  alias_method_chain :_create_record, :bullet
58
61
  end
@@ -45,7 +45,10 @@ module Bullet
45
45
 
46
46
  ::ActiveRecord::Persistence.class_eval do
47
47
  def _create_record_with_bullet(*args)
48
- _create_record_without_bullet(*args).tap { Bullet::Detector::NPlusOneQuery.update_inversed_object(self) }
48
+ _create_record_without_bullet(*args).tap do
49
+ Bullet::Detector::NPlusOneQuery.update_inversed_object(self)
50
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
51
+ end
49
52
  end
50
53
  alias_method_chain :_create_record, :bullet
51
54
  end
@@ -5,6 +5,7 @@ module Bullet
5
5
  def _create_record(*)
6
6
  super do
7
7
  Bullet::Detector::NPlusOneQuery.update_inversed_object(self)
8
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
8
9
  yield(self) if block_given?
9
10
  end
10
11
  end
@@ -5,6 +5,7 @@ module Bullet
5
5
  def _create_record(*)
6
6
  super do
7
7
  Bullet::Detector::NPlusOneQuery.update_inversed_object(self)
8
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
8
9
  yield(self) if block_given?
9
10
  end
10
11
  end
@@ -5,6 +5,7 @@ module Bullet
5
5
  def _create_record(*)
6
6
  super do
7
7
  Bullet::Detector::NPlusOneQuery.update_inversed_object(self)
8
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
8
9
  yield(self) if block_given?
9
10
  end
10
11
  end
@@ -5,6 +5,7 @@ module Bullet
5
5
  def _create_record(*)
6
6
  super do
7
7
  Bullet::Detector::NPlusOneQuery.update_inversed_object(self)
8
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
8
9
  yield(self) if block_given?
9
10
  end
10
11
  end
@@ -5,6 +5,7 @@ module Bullet
5
5
  def _create_record(*)
6
6
  super do
7
7
  Bullet::Detector::NPlusOneQuery.update_inversed_object(self)
8
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
8
9
  yield(self) if block_given?
9
10
  end
10
11
  end
@@ -5,6 +5,7 @@ module Bullet
5
5
  def _create_record(*)
6
6
  super do
7
7
  Bullet::Detector::NPlusOneQuery.update_inversed_object(self)
8
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
8
9
  yield(self) if block_given?
9
10
  end
10
11
  end
@@ -5,6 +5,7 @@ module Bullet
5
5
  def _create_record(*)
6
6
  super do
7
7
  Bullet::Detector::NPlusOneQuery.update_inversed_object(self)
8
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
8
9
  yield(self) if block_given?
9
10
  end
10
11
  end
@@ -5,6 +5,7 @@ module Bullet
5
5
  def _create_record(*)
6
6
  super do
7
7
  Bullet::Detector::NPlusOneQuery.update_inversed_object(self)
8
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
8
9
  yield(self) if block_given?
9
10
  end
10
11
  end
data/lib/bullet/rack.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rack/request'
4
+ require 'json'
5
+
3
6
  module Bullet
4
7
  class Rack
5
8
  include Dependency
@@ -19,7 +22,8 @@ module Bullet
19
22
  response_body = nil
20
23
 
21
24
  if Bullet.notification? || Bullet.always_append_html_body
22
- if Bullet.inject_into_page? && !file?(headers) && !sse?(headers) && !empty?(response) && status == 200
25
+ request = ::Rack::Request.new(env)
26
+ if Bullet.inject_into_page? && !skip_html_injection?(request) && !file?(headers) && !sse?(headers) && !empty?(response) && status == 200
23
27
  if html_request?(headers, response)
24
28
  response_body = response_body(response)
25
29
 
@@ -73,8 +77,23 @@ module Bullet
73
77
  # Many proxy applications such as Nginx and AWS ELB limit
74
78
  # the size a header to 8KB, so truncate the list of reports to
75
79
  # be under that limit
76
- header_array.pop while header_array.to_json.length > 8 * 1024
77
- headers[header_name] = header_array.to_json
80
+ header_array.pop while JSON.generate(header_array).length > 8 * 1024
81
+ headers[header_name] = JSON.generate(header_array)
82
+ end
83
+
84
+ def skip_html_injection?(request)
85
+ query_string = request.env['QUERY_STRING']
86
+ return false if query_string.nil? || query_string.empty?
87
+
88
+ if defined?(Rack::QueryParser)
89
+ parser = Rack::QueryParser.new
90
+ params = parser.parse_nested_query(query_string)
91
+ else
92
+ # compatible with rack 1.x,
93
+ # remove it after dropping rails 4.2 suppport
94
+ params = Rack::Utils.parse_nested_query(query_string)
95
+ end
96
+ params['skip_html_injection'] == 'true'
78
97
  end
79
98
 
80
99
  def file?(headers)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bullet
4
- VERSION = '8.0.3'
4
+ VERSION = '8.0.4'
5
5
  end
data/lib/bullet.rb CHANGED
@@ -24,7 +24,7 @@ module Bullet
24
24
  if defined?(Rails::Railtie)
25
25
  class BulletRailtie < Rails::Railtie
26
26
  initializer 'bullet.configure_rails_initialization' do |app|
27
- if defined?(ActionDispatch::ContentSecurityPolicy::Middleware) && Rails.application.config.content_security_policy
27
+ if defined?(ActionDispatch::ContentSecurityPolicy::Middleware)
28
28
  app.middleware.insert_before ActionDispatch::ContentSecurityPolicy::Middleware, Bullet::Rack
29
29
  else
30
30
  app.middleware.use Bullet::Rack
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullet
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.0.3
4
+ version: 8.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-04 00:00:00.000000000 Z
10
+ date: 2025-04-18 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activesupport