From f835c5f6aaffe4f2ccbc90b596fe956190615e5f Mon Sep 17 00:00:00 2001 From: Alexey Mahotkin Date: Sat, 11 Mar 2017 18:56:35 +0100 Subject: [PATCH] Use " => '' } # This is the props used by the React component. @app_props_server_render = { helloWorldData: { name: "Mr. Server Side Rendering" - } + }.merge(xss_payload) } @app_props_hello = { helloWorldData: { name: "Mrs. Client Side Rendering" - } + }.merge(xss_payload) } @app_props_hello_again = { helloWorldData: { name: "Mrs. Client Side Hello Again" - } + }.merge(xss_payload) } end end diff --git a/spec/dummy/app/views/pages/server_side_hello_world_with_options.html.erb b/spec/dummy/app/views/pages/server_side_hello_world_with_options.html.erb index 00d8463bd..b1fcdc506 100644 --- a/spec/dummy/app/views/pages/server_side_hello_world_with_options.html.erb +++ b/spec/dummy/app/views/pages/server_side_hello_world_with_options.html.erb @@ -1,7 +1,7 @@ <%= render "header" %> <%= react_component("HelloWorld", - props: @app_props_server_render.to_json, + props: @app_props_server_render, prerender: true, trace: true, id: "my-hello-world-id", @@ -27,7 +27,7 @@
 <%%= react_component("HelloWorld",
-                    props: @app_props_server_render.to_json,
+                    props: @app_props_server_render,
                     prerender: true,
                     trace: true,
                     id: "my-hello-world-id",
diff --git a/spec/dummy/config/initializers/react_on_rails.rb b/spec/dummy/config/initializers/react_on_rails.rb
index f237bef7a..540c192b8 100644
--- a/spec/dummy/config/initializers/react_on_rails.rb
+++ b/spec/dummy/config/initializers/react_on_rails.rb
@@ -81,8 +81,6 @@ def self.custom_context(view_context)
   ################################################################################
   # MISCELLANEOUS OPTIONS
   ################################################################################
-  # Default is false, enable if your content security policy doesn't include `style-src: 'unsafe-inline'`
-  config.skip_display_none = false
 
   # This allows you to add additional values to the Rails Context. Implement one static method
   # called `custom_context(view_context)` and return a Hash.
diff --git a/spec/dummy/spec/helpers/react_on_rails_helper_spec.rb b/spec/dummy/spec/helpers/react_on_rails_helper_spec.rb
index b212c2d46..de97c706b 100644
--- a/spec/dummy/spec/helpers/react_on_rails_helper_spec.rb
+++ b/spec/dummy/spec/helpers/react_on_rails_helper_spec.rb
@@ -59,76 +59,44 @@
 
     let(:id) { "App-react-component-0" }
 
-    let(:react_definition_div) do
-      %().squish
+    # rubocop:disable Metrics/LineLength
+    let(:react_definition_script) do
+      %().squish
     end
 
-    let(:react_definition_div_no_params) do
-      %().squish
+    let(:react_definition_script_no_params) do
+      %().squish
     end
+    # rubocop:enable Metrics/LineLength
 
     describe "API with component name only" do
       subject { react_component("App") }
       it { is_expected.to be_an_instance_of ActiveSupport::SafeBuffer }
       it { is_expected.to include react_component_div }
-      it { is_expected.to include react_definition_div_no_params }
+      it { is_expected.to include react_definition_script_no_params }
     end
 
     it { expect(self).to respond_to :react_component }
 
     it { is_expected.to be_an_instance_of ActiveSupport::SafeBuffer }
-    it { is_expected.to start_with "\s*$} }
+    it { is_expected.to start_with "\s*$} }
     it { is_expected.to include react_component_div }
-    it { is_expected.to include react_definition_div }
+    it { is_expected.to include react_definition_script }
 
     context "with 'id' option" do
       subject { react_component("App", props: props, id: id) }
 
       let(:id) { "shaka_div" }
 
-      it { is_expected.to include id }
-      it { is_expected.not_to include react_component_div }
-      it { is_expected.to include react_definition_div }
-    end
-
-    context "with skip_display_none option true" do
-      before { ReactOnRails.configuration.skip_display_none = true }
-
-      let(:react_definition_div_skip_display_none_true) do
-        "
".squish - end - - it { is_expected.to include react_definition_div_skip_display_none_true } - end - - context "with skip_display_none option false" do - before { ReactOnRails.configuration.skip_display_none = false } - - let(:react_definition_div_skip_display_none_false) do - "
".squish + let(:react_definition_script) do + # rubocop:disable Metrics/LineLength + %().squish end - it { is_expected.to include react_definition_div_skip_display_none_false } + it { is_expected.to include id } + it { is_expected.not_to include react_component_div } + it { is_expected.to include react_definition_script } end end @@ -139,36 +107,16 @@ { name: "My Test Name" } end - let(:react_store_div) do - %().squish + let(:react_store_script) do + %().squish end it { expect(self).to respond_to :redux_store } it { is_expected.to be_an_instance_of ActiveSupport::SafeBuffer } - it { is_expected.to start_with "" } - it { is_expected.to include react_store_div } - - context "with skip_display_none option true" do - before { ReactOnRails.configuration.skip_display_none = true } - - let(:react_store_definition_div_skip_display_none_true) do - %(
).squish - end - - it { is_expected.to include react_store_definition_div_skip_display_none_true } - end - - context "with skip_display_none option false" do - before { ReactOnRails.configuration.skip_display_none = false } - it { is_expected.to include react_store_div } - end + it { is_expected.to start_with "" } + it { is_expected.to include react_store_script } end describe "#server_render_js" do diff --git a/spec/dummy/spec/requests/server_render_check_spec.rb b/spec/dummy/spec/requests/server_render_check_spec.rb index 57c533375..6564d1e98 100644 --- a/spec/dummy/spec/requests/server_render_check_spec.rb +++ b/spec/dummy/spec/requests/server_render_check_spec.rb @@ -63,14 +63,14 @@ mail = DummyMailer.hello_email expect(mail.subject).to match "mail" expect(mail.body).to match "Mr. Mailing Server Side Rendering" - expect(mail.body).to match "inMailer":true" + expect(mail.body).to match "\"inMailer\":true" end it "sets inMailer properly" do get client_side_hello_world_path html_nodes = Nokogiri::HTML(response.body) - expect(html_nodes.css("div#js-react-on-rails-context").attr("data-rails-context").value) - .to match('inMailer\":false') + expect(html_nodes.at_css("script#js-react-on-rails-context").content) + .to match("\"inMailer\":false") end end diff --git a/spec/react_on_rails/configuration_spec.rb b/spec/react_on_rails/configuration_spec.rb index 6169b5a17..050fef62f 100644 --- a/spec/react_on_rails/configuration_spec.rb +++ b/spec/react_on_rails/configuration_spec.rb @@ -40,18 +40,5 @@ module ReactOnRails expect(ReactOnRails.configuration.server_bundle_js_file).to eq("something.js") expect(ReactOnRails.configuration.prerender).to eq(true) end - - context "skip display: none" do - it "will default false" do - expect(ReactOnRails.configuration.skip_display_none).to eq(false) - end - - it "will be true if set to true" do - ReactOnRails.configure do |config| - config.skip_display_none = true - end - expect(ReactOnRails.configuration.skip_display_none).to eq(true) - end - end end end diff --git a/spec/react_on_rails/react_component/options_spec.rb b/spec/react_on_rails/react_component/options_spec.rb index f5311a46c..63670226a 100644 --- a/spec/react_on_rails/react_component/options_spec.rb +++ b/spec/react_on_rails/react_component/options_spec.rb @@ -137,30 +137,6 @@ def the_attrs(name: "App", options: {}) end end - describe "#style" do - context "skipped display none" do - it "returns nil" do - ReactOnRails.configuration.skip_display_none = true - attrs = the_attrs - - opts = described_class.new(attrs) - - expect(opts.style).to eq nil - end - end - - context "not skipped display none" do - it "returns value" do - ReactOnRails.configuration.skip_display_none = false - attrs = the_attrs - - opts = described_class.new(attrs) - - expect(opts.style).to eq "display:none" - end - end - end - CONFIGURABLE_OPTIONS.each do |option| describe "##{option}" do context "with #{option} option" do