diff --git a/CHANGELOG.md b/CHANGELOG.md index e39ce1d..d67b514 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.7.0 + + * [ENHANCEMENT] support frozen string literals (also: avoid RuntimeError in Rack::Tracker#inject #114 thx @zpfled) + # 1.6.0 * [BUGFIX] set wildcard to non-greedy for GTM body insertion #107 diff --git a/Rakefile b/Rakefile index c382fee..c38f0b1 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "bundler/gem_tasks" require 'rspec/core/rake_task' diff --git a/lib/rack/tracker.rb b/lib/rack/tracker.rb index f2141f0..5b8a947 100644 --- a/lib/rack/tracker.rb +++ b/lib/rack/tracker.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "rack" require "tilt" require "active_support/core_ext/class/attribute" diff --git a/lib/rack/tracker/controller.rb b/lib/rack/tracker/controller.rb index 801a52a..79464fc 100644 --- a/lib/rack/tracker/controller.rb +++ b/lib/rack/tracker/controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Rack class Tracker module Controller diff --git a/lib/rack/tracker/criteo/criteo.rb b/lib/rack/tracker/criteo/criteo.rb index 5a71c7b..91736cb 100644 --- a/lib/rack/tracker/criteo/criteo.rb +++ b/lib/rack/tracker/criteo/criteo.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Rack::Tracker::Criteo < Rack::Tracker::Handler TRACKER_EVENTS = { diff --git a/lib/rack/tracker/extensions.rb b/lib/rack/tracker/extensions.rb index bfbe832..951def0 100644 --- a/lib/rack/tracker/extensions.rb +++ b/lib/rack/tracker/extensions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'ostruct' # Backport of 2.0.0 stdlib ostruct#to_h diff --git a/lib/rack/tracker/facebook/facebook.rb b/lib/rack/tracker/facebook/facebook.rb index 67a9311..8b59749 100644 --- a/lib/rack/tracker/facebook/facebook.rb +++ b/lib/rack/tracker/facebook/facebook.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Rack::Tracker::Facebook < Rack::Tracker::Handler class Event < OpenStruct def write diff --git a/lib/rack/tracker/facebook_pixel/facebook_pixel.rb b/lib/rack/tracker/facebook_pixel/facebook_pixel.rb index f6015dd..b182c86 100644 --- a/lib/rack/tracker/facebook_pixel/facebook_pixel.rb +++ b/lib/rack/tracker/facebook_pixel/facebook_pixel.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Rack::Tracker::FacebookPixel < Rack::Tracker::Handler self.position = :body self.allowed_tracker_options = [:id] diff --git a/lib/rack/tracker/go_squared/go_squared.rb b/lib/rack/tracker/go_squared/go_squared.rb index 7885d0a..8ea87df 100644 --- a/lib/rack/tracker/go_squared/go_squared.rb +++ b/lib/rack/tracker/go_squared/go_squared.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Rack::Tracker::GoSquared < Rack::Tracker::Handler class VisitorName < OpenStruct def write diff --git a/lib/rack/tracker/google_adwords_conversion/google_adwords_conversion.rb b/lib/rack/tracker/google_adwords_conversion/google_adwords_conversion.rb index ecdf652..f765ffc 100644 --- a/lib/rack/tracker/google_adwords_conversion/google_adwords_conversion.rb +++ b/lib/rack/tracker/google_adwords_conversion/google_adwords_conversion.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Rack::Tracker::GoogleAdwordsConversion < Rack::Tracker::Handler class Conversion < OpenStruct end diff --git a/lib/rack/tracker/google_analytics/google_analytics.rb b/lib/rack/tracker/google_analytics/google_analytics.rb index a359cc1..3fbfc9a 100644 --- a/lib/rack/tracker/google_analytics/google_analytics.rb +++ b/lib/rack/tracker/google_analytics/google_analytics.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Rack::Tracker::GoogleAnalytics < Rack::Tracker::Handler self.allowed_tracker_options = [:cookie_domain, :user_id] diff --git a/lib/rack/tracker/google_tag_manager/google_tag_manager.rb b/lib/rack/tracker/google_tag_manager/google_tag_manager.rb index 2db9d2b..8784301 100644 --- a/lib/rack/tracker/google_tag_manager/google_tag_manager.rb +++ b/lib/rack/tracker/google_tag_manager/google_tag_manager.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Rack::Tracker::GoogleTagManager < Rack::Tracker::Handler class Push < OpenStruct diff --git a/lib/rack/tracker/handler.rb b/lib/rack/tracker/handler.rb index 25c7788..0a3d869 100644 --- a/lib/rack/tracker/handler.rb +++ b/lib/rack/tracker/handler.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Rack::Tracker::Handler class << self def process_track(env, method_name, *args, &block) diff --git a/lib/rack/tracker/handler_delegator.rb b/lib/rack/tracker/handler_delegator.rb index f968fa9..99beac8 100644 --- a/lib/rack/tracker/handler_delegator.rb +++ b/lib/rack/tracker/handler_delegator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Rack::Tracker::HandlerDelegator class << self def handler(method_name) diff --git a/lib/rack/tracker/hotjar/hotjar.rb b/lib/rack/tracker/hotjar/hotjar.rb index 482e5d3..8635587 100644 --- a/lib/rack/tracker/hotjar/hotjar.rb +++ b/lib/rack/tracker/hotjar/hotjar.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class Rack::Tracker::Hotjar < Rack::Tracker::Handler end diff --git a/lib/rack/tracker/javascript_helper.rb b/lib/rack/tracker/javascript_helper.rb index 02ccdfb..8314563 100644 --- a/lib/rack/tracker/javascript_helper.rb +++ b/lib/rack/tracker/javascript_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This module is extracted from Rails to provide reliable javascript escaping. # # @see https://github.com/rails/rails/blob/master/actionview/lib/action_view/helpers/javascript_helper.rb @@ -13,8 +15,8 @@ module Rack::Tracker::JavaScriptHelper "'" => "\\'" } - JS_ESCAPE_MAP["\342\200\250".force_encoding(Encoding::UTF_8).encode!] = '
' - JS_ESCAPE_MAP["\342\200\251".force_encoding(Encoding::UTF_8).encode!] = '
' + JS_ESCAPE_MAP["\342\200\250".dup.force_encoding(Encoding::UTF_8).encode!] = '
' + JS_ESCAPE_MAP["\342\200\251".dup.force_encoding(Encoding::UTF_8).encode!] = '
' # Escapes carriage returns and single and double quotes for JavaScript segments. # diff --git a/lib/rack/tracker/railtie.rb b/lib/rack/tracker/railtie.rb index 965cb73..fd1bfbe 100644 --- a/lib/rack/tracker/railtie.rb +++ b/lib/rack/tracker/railtie.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Rack class Tracker class Railtie < ::Rails::Railtie diff --git a/lib/rack/tracker/version.rb b/lib/rack/tracker/version.rb index 750100f..5a84956 100644 --- a/lib/rack/tracker/version.rb +++ b/lib/rack/tracker/version.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + module Rack class Tracker - VERSION = '1.6.0' + VERSION = '1.7.0' end end diff --git a/lib/rack/tracker/vwo/vwo.rb b/lib/rack/tracker/vwo/vwo.rb index c7fdfa3..71be6a6 100644 --- a/lib/rack/tracker/vwo/vwo.rb +++ b/lib/rack/tracker/vwo/vwo.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class Rack::Tracker::Vwo < Rack::Tracker::Handler end diff --git a/lib/rack/tracker/zanox/zanox.rb b/lib/rack/tracker/zanox/zanox.rb index a674b6f..49e31db 100644 --- a/lib/rack/tracker/zanox/zanox.rb +++ b/lib/rack/tracker/zanox/zanox.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Rack::Tracker::Zanox < Rack::Tracker::Handler # name of the handler diff --git a/spec/benchmark/tracker_injection_benchmark.rb b/spec/benchmark/tracker_injection_benchmark.rb index 2874eb1..f986b5e 100644 --- a/spec/benchmark/tracker_injection_benchmark.rb +++ b/spec/benchmark/tracker_injection_benchmark.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'support/capybara_app_helper' require 'benchmark' diff --git a/spec/handler/criteo_spec.rb b/spec/handler/criteo_spec.rb index 8feded3..b0c526a 100644 --- a/spec/handler/criteo_spec.rb +++ b/spec/handler/criteo_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Rack::Tracker::Criteo do describe Rack::Tracker::Criteo::Event do diff --git a/spec/handler/facebook_pixel_spec.rb b/spec/handler/facebook_pixel_spec.rb index 9716529..e1f28dd 100644 --- a/spec/handler/facebook_pixel_spec.rb +++ b/spec/handler/facebook_pixel_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Rack::Tracker::FacebookPixel do def env { 'PIXEL_ID' => 'DYNAMIC_PIXEL_ID' } diff --git a/spec/handler/facebook_spec.rb b/spec/handler/facebook_spec.rb index 6a24738..bd8f115 100644 --- a/spec/handler/facebook_spec.rb +++ b/spec/handler/facebook_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Rack::Tracker::Facebook do describe Rack::Tracker::Facebook::Event do diff --git a/spec/handler/go_squared_spec.rb b/spec/handler/go_squared_spec.rb index 4d15bab..aebe3c7 100644 --- a/spec/handler/go_squared_spec.rb +++ b/spec/handler/go_squared_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Rack::Tracker::GoSquared do def env diff --git a/spec/handler/google_adwords_conversion_spec.rb b/spec/handler/google_adwords_conversion_spec.rb index 52536cf..fbdbf5a 100644 --- a/spec/handler/google_adwords_conversion_spec.rb +++ b/spec/handler/google_adwords_conversion_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Rack::Tracker::GoogleAdwordsConversion do def env diff --git a/spec/handler/google_analytics_spec.rb b/spec/handler/google_analytics_spec.rb index 027b7a8..e012e3a 100644 --- a/spec/handler/google_analytics_spec.rb +++ b/spec/handler/google_analytics_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Rack::Tracker::GoogleAnalytics do def env { diff --git a/spec/handler/google_tag_manager_spec.rb b/spec/handler/google_tag_manager_spec.rb index ed1e147..a643e47 100644 --- a/spec/handler/google_tag_manager_spec.rb +++ b/spec/handler/google_tag_manager_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Rack::Tracker::GoogleTagManager do def env diff --git a/spec/handler/handler_spec.rb b/spec/handler/handler_spec.rb index 2fabeff..e00e1aa 100644 --- a/spec/handler/handler_spec.rb +++ b/spec/handler/handler_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Rack::Tracker::Handler do def env { misc: 'foobar' } diff --git a/spec/handler/hotjar_spec.rb b/spec/handler/hotjar_spec.rb index c4a5855..698df29 100644 --- a/spec/handler/hotjar_spec.rb +++ b/spec/handler/hotjar_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Rack::Tracker::Hotjar do def env { foo: 'bar' } diff --git a/spec/handler/vwo_spec.rb b/spec/handler/vwo_spec.rb index 5b4fab6..4b03f87 100644 --- a/spec/handler/vwo_spec.rb +++ b/spec/handler/vwo_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Rack::Tracker::Vwo do def env diff --git a/spec/handler/zanox_spec.rb b/spec/handler/zanox_spec.rb index dbf374d..438eb5c 100644 --- a/spec/handler/zanox_spec.rb +++ b/spec/handler/zanox_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Rack::Tracker::Zanox do describe Rack::Tracker::Zanox::Sale do diff --git a/spec/integration/criteo_integration_spec.rb b/spec/integration/criteo_integration_spec.rb index aa3df67..9c8977a 100644 --- a/spec/integration/criteo_integration_spec.rb +++ b/spec/integration/criteo_integration_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'support/capybara_app_helper' RSpec.describe "Criteo Integration" do diff --git a/spec/integration/facebook_integration_spec.rb b/spec/integration/facebook_integration_spec.rb index 456359a..dd9f416 100644 --- a/spec/integration/facebook_integration_spec.rb +++ b/spec/integration/facebook_integration_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'support/capybara_app_helper' RSpec.describe "Facebook Integration" do diff --git a/spec/integration/facebook_pixel_integration_spec.rb b/spec/integration/facebook_pixel_integration_spec.rb index 07af9f0..03b0586 100644 --- a/spec/integration/facebook_pixel_integration_spec.rb +++ b/spec/integration/facebook_pixel_integration_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'support/capybara_app_helper' RSpec.describe "Facebook Pixel Integration" do diff --git a/spec/integration/go_squared_integration_spec.rb b/spec/integration/go_squared_integration_spec.rb index d530c6d..d3f8b51 100644 --- a/spec/integration/go_squared_integration_spec.rb +++ b/spec/integration/go_squared_integration_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'support/capybara_app_helper' RSpec.describe "GoSquared Integration" do diff --git a/spec/integration/google_adwords_conversion_integration_spec.rb b/spec/integration/google_adwords_conversion_integration_spec.rb index 2e64ce9..8e93bc7 100644 --- a/spec/integration/google_adwords_conversion_integration_spec.rb +++ b/spec/integration/google_adwords_conversion_integration_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'support/capybara_app_helper' RSpec.describe "Google Adwords Conversion Integration" do diff --git a/spec/integration/google_analytics_integration_spec.rb b/spec/integration/google_analytics_integration_spec.rb index 7f5888a..5bffdaa 100644 --- a/spec/integration/google_analytics_integration_spec.rb +++ b/spec/integration/google_analytics_integration_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'support/capybara_app_helper' RSpec.describe "Google Analytics Integration" do diff --git a/spec/integration/google_tag_manager_integration_spec.rb b/spec/integration/google_tag_manager_integration_spec.rb index f8fe375..5b9dc12 100644 --- a/spec/integration/google_tag_manager_integration_spec.rb +++ b/spec/integration/google_tag_manager_integration_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'support/capybara_app_helper' RSpec.describe "Google Tag Manager Integration" do diff --git a/spec/integration/hotjar_integration_spec.rb b/spec/integration/hotjar_integration_spec.rb index 301a801..e176a67 100644 --- a/spec/integration/hotjar_integration_spec.rb +++ b/spec/integration/hotjar_integration_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'support/capybara_app_helper' RSpec.describe "Hotjar Integration" do diff --git a/spec/integration/rails_integration_spec.rb b/spec/integration/rails_integration_spec.rb index 368efbe..f1c3b49 100644 --- a/spec/integration/rails_integration_spec.rb +++ b/spec/integration/rails_integration_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'support/capybara_app_helper' RSpec.describe "Rails Integration" do diff --git a/spec/integration/vwo_integration_spec.rb b/spec/integration/vwo_integration_spec.rb index 80807ce..366511b 100644 --- a/spec/integration/vwo_integration_spec.rb +++ b/spec/integration/vwo_integration_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'support/capybara_app_helper' RSpec.describe "VWO Integration" do diff --git a/spec/integration/zanox_integration_spec.rb b/spec/integration/zanox_integration_spec.rb index b1f5f4b..fe8fa21 100644 --- a/spec/integration/zanox_integration_spec.rb +++ b/spec/integration/zanox_integration_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'support/capybara_app_helper' RSpec.describe "Zanox Integration" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 39b3f24..c0d276d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.dirname(__FILE__)) diff --git a/spec/support/capybara_app_helper.rb b/spec/support/capybara_app_helper.rb index 3125e9c..354870d 100644 --- a/spec/support/capybara_app_helper.rb +++ b/spec/support/capybara_app_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'support/metal_controller' # helper to configure the middleware stack with custom handlers diff --git a/spec/support/fake_handler.rb b/spec/support/fake_handler.rb index c40c1e5..d17c4f2 100644 --- a/spec/support/fake_handler.rb +++ b/spec/support/fake_handler.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class TrackAllTheThings < Rack::Tracker::Handler def render Tilt.new( File.join( File.dirname(__FILE__), '../fixtures/track_all_the_things.erb') ).render(self) diff --git a/spec/support/metal_controller.rb b/spec/support/metal_controller.rb index b7241c7..4a4c335 100644 --- a/spec/support/metal_controller.rb +++ b/spec/support/metal_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'action_controller' class MetalController < ActionController::Metal diff --git a/spec/tracker/controller_spec.rb b/spec/tracker/controller_spec.rb index 52d30b2..6f523ff 100644 --- a/spec/tracker/controller_spec.rb +++ b/spec/tracker/controller_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + TestController = Struct.new(:env) do include Rack::Tracker::Controller diff --git a/spec/tracker/handler_delegator_spec.rb b/spec/tracker/handler_delegator_spec.rb index 2fa2bb8..0e7afd3 100644 --- a/spec/tracker/handler_delegator_spec.rb +++ b/spec/tracker/handler_delegator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Foo = Class.new Bar = Class.new diff --git a/spec/tracker/handler_set_spec.rb b/spec/tracker/handler_set_spec.rb index e3f411c..f69dff2 100644 --- a/spec/tracker/handler_set_spec.rb +++ b/spec/tracker/handler_set_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Dummy < Rack::Tracker::Handler end diff --git a/spec/tracker/javascript_helper_spec.rb b/spec/tracker/javascript_helper_spec.rb index fc36815..787661c 100644 --- a/spec/tracker/javascript_helper_spec.rb +++ b/spec/tracker/javascript_helper_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Rack::Tracker do let(:escaper) do @@ -39,13 +41,11 @@ it { should escape(%(This "thing" is really\n netos')).to %(This \\"thing\\" is really\\n netos\\') } it { should escape(%(backslash\\test)).to %(backslash\\\\test) } it { should escape(%(dont tags)).to %(dont <\\/close> tags) } - it { should escape(%(unicode \342\200\250 newline).force_encoding(Encoding::UTF_8).encode!).to %(unicode 
 newline) } - it { should escape(%(unicode \342\200\251 newline).force_encoding(Encoding::UTF_8).encode!).to %(unicode 
 newline) } + it { should escape(%(unicode \342\200\250 newline).dup.force_encoding(Encoding::UTF_8).encode!).to %(unicode 
 newline) } + it { should escape(%(unicode \342\200\251 newline).dup.force_encoding(Encoding::UTF_8).encode!).to %(unicode 
 newline) } it 'works with symbols' do expect(subject).to escape(:dimension1).to 'dimension1' end - end - -end \ No newline at end of file +end diff --git a/spec/tracker/tracker_spec.rb b/spec/tracker/tracker_spec.rb index 664e6c1..38caa8c 100644 --- a/spec/tracker/tracker_spec.rb +++ b/spec/tracker/tracker_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class DummyHandler < Rack::Tracker::Handler def render Tilt.new( File.join( File.dirname(__FILE__), '../fixtures/dummy.erb') ).render(self)