Skip to content

Commit

Permalink
Remove JsonOutput.escape workaround for Rails < 4.1.1 (#1580)
Browse files Browse the repository at this point in the history
* Remove JsonOutput.escape workaround for Rails<4.1.1

* Remove unused Utils.rails_version_less_than_4_1_1

* Updated CHANGELOG.md

* remove escape_without_erb_util test

---------

Co-authored-by: Judah Meek <[email protected]>
  • Loading branch information
wwahammy and Judahmeek authored Nov 15, 2023
1 parent 14f8633 commit 99be556
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 48 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Please follow the recommendations outlined at [keepachangelog.com](http://keepac
### [Unreleased]
Changes since the last non-beta release.

*Please add entries here for your pull requests that are not yet released.*
- Removed a workaround in `JsonOutput#escape` for an no-longer supported Rails version. Additionally, removed `Utils.rails_version_less_than_4_1_1`
which was only used in the workaround. [PR 1580](https://github.com/shakacode/react_on_rails/pull/1580) by [wwahammy](https://github.com/wwahammy)

### [13.4.0] - 2023-07-30
#### Fixed
- Fixed Pack Generation logic during `assets:precompile` if `auto_load_bundle` is `false` & `components_subdirectory` is not set. [PR 1567](https://github.com/shakacode/react_on_rails/pull/1545) by [blackjack26](https://github.com/blackjack26) & [judahmeek](https://github.com/judahmeek).
Expand Down
17 changes: 0 additions & 17 deletions lib/react_on_rails/json_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,8 @@

module ReactOnRails
class JsonOutput
ESCAPE_REPLACEMENT = {
"&" => '\u0026',
">" => '\u003e',
"<" => '\u003c',
"\u2028" => '\u2028',
"\u2029" => '\u2029'
}.freeze
ESCAPE_REGEXP = /[\u2028\u2029&><]/u.freeze

def self.escape(json)
return escape_without_erb_util(json) if Utils.rails_version_less_than_4_1_1

ERB::Util.json_escape(json)
end

def self.escape_without_erb_util(json)
# https://github.com/rails/rails/blob/60257141462137331387d0e34931555cf0720886/activesupport/lib/active_support/core_ext/string/output_safety.rb#L113

json.to_s.gsub(ESCAPE_REGEXP, ESCAPE_REPLACEMENT)
end
end
end
6 changes: 0 additions & 6 deletions lib/react_on_rails/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,6 @@ def self.rails_version_less_than(version)
end
end

# rubocop:disable Naming/VariableNumber
def self.rails_version_less_than_4_1_1
rails_version_less_than("4.1.1")
end
# rubocop:enable Naming/VariableNumber

module Required
def required(arg_name)
raise ReactOnRails::Error, "#{arg_name} is required"
Expand Down
6 changes: 0 additions & 6 deletions spec/react_on_rails/json_output_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,5 @@ module ReactOnRails

it_behaves_like "escaped json"
end

describe ".escaped_without_erb_utils" do
subject { described_class.escape_without_erb_util(hash_value.to_json) }

it_behaves_like "escaped json"
end
end
end
18 changes: 0 additions & 18 deletions spec/react_on_rails/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,24 +301,6 @@ module ReactOnRails
end
end
end

describe ".rails_version_less_than_4_1_1" do
subject { described_class.rails_version_less_than_4_1_1 }

before { described_class.instance_variable_set :@rails_version_less_than, nil }

context "with Rails 4.1.0" do
before { allow(Rails).to receive(:version).and_return("4.1.0") }

it { is_expected.to be(true) }
end

context "with Rails 4.1.1" do
before { allow(Rails).to receive(:version).and_return("4.1.1") }

it { is_expected.to be(false) }
end
end
end

describe ".smart_trim" do
Expand Down

0 comments on commit 99be556

Please sign in to comment.