Skip to content

Commit 99be556

Browse files
wwahammyJudahmeek
andauthored
Remove JsonOutput.escape workaround for Rails < 4.1.1 (#1580)
* 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]>
1 parent 14f8633 commit 99be556

File tree

5 files changed

+3
-48
lines changed

5 files changed

+3
-48
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ Please follow the recommendations outlined at [keepachangelog.com](http://keepac
1515
### [Unreleased]
1616
Changes since the last non-beta release.
1717

18-
*Please add entries here for your pull requests that are not yet released.*
18+
- Removed a workaround in `JsonOutput#escape` for an no-longer supported Rails version. Additionally, removed `Utils.rails_version_less_than_4_1_1`
19+
which was only used in the workaround. [PR 1580](https://github.com/shakacode/react_on_rails/pull/1580) by [wwahammy](https://github.com/wwahammy)
20+
1921
### [13.4.0] - 2023-07-30
2022
#### Fixed
2123
- 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).

lib/react_on_rails/json_output.rb

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,8 @@
44

55
module ReactOnRails
66
class JsonOutput
7-
ESCAPE_REPLACEMENT = {
8-
"&" => '\u0026',
9-
">" => '\u003e',
10-
"<" => '\u003c',
11-
"\u2028" => '\u2028',
12-
"\u2029" => '\u2029'
13-
}.freeze
14-
ESCAPE_REGEXP = /[\u2028\u2029&><]/u.freeze
15-
167
def self.escape(json)
17-
return escape_without_erb_util(json) if Utils.rails_version_less_than_4_1_1
18-
198
ERB::Util.json_escape(json)
209
end
21-
22-
def self.escape_without_erb_util(json)
23-
# https://github.com/rails/rails/blob/60257141462137331387d0e34931555cf0720886/activesupport/lib/active_support/core_ext/string/output_safety.rb#L113
24-
25-
json.to_s.gsub(ESCAPE_REGEXP, ESCAPE_REPLACEMENT)
26-
end
2710
end
2811
end

lib/react_on_rails/utils.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,6 @@ def self.rails_version_less_than(version)
118118
end
119119
end
120120

121-
# rubocop:disable Naming/VariableNumber
122-
def self.rails_version_less_than_4_1_1
123-
rails_version_less_than("4.1.1")
124-
end
125-
# rubocop:enable Naming/VariableNumber
126-
127121
module Required
128122
def required(arg_name)
129123
raise ReactOnRails::Error, "#{arg_name} is required"

spec/react_on_rails/json_output_spec.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,5 @@ module ReactOnRails
2727

2828
it_behaves_like "escaped json"
2929
end
30-
31-
describe ".escaped_without_erb_utils" do
32-
subject { described_class.escape_without_erb_util(hash_value.to_json) }
33-
34-
it_behaves_like "escaped json"
35-
end
3630
end
3731
end

spec/react_on_rails/utils_spec.rb

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -301,24 +301,6 @@ module ReactOnRails
301301
end
302302
end
303303
end
304-
305-
describe ".rails_version_less_than_4_1_1" do
306-
subject { described_class.rails_version_less_than_4_1_1 }
307-
308-
before { described_class.instance_variable_set :@rails_version_less_than, nil }
309-
310-
context "with Rails 4.1.0" do
311-
before { allow(Rails).to receive(:version).and_return("4.1.0") }
312-
313-
it { is_expected.to be(true) }
314-
end
315-
316-
context "with Rails 4.1.1" do
317-
before { allow(Rails).to receive(:version).and_return("4.1.1") }
318-
319-
it { is_expected.to be(false) }
320-
end
321-
end
322304
end
323305

324306
describe ".smart_trim" do

0 commit comments

Comments
 (0)