Skip to content

Commit 4bdb337

Browse files
authoredOct 20, 2024
Merge pull request #719 from chaadow/patch-1
Fix frozen string literal for ruby 3.4
2 parents eefc42d + 1ed51d0 commit 4bdb337

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed
 

‎.github/workflows/ci.yml

+9-10
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,20 @@ jobs:
66
strategy:
77
fail-fast: false
88
matrix:
9-
ruby: [ '3.1', '3.2', '3.3', 'head' ]
9+
ruby: [ '3.1', '3.2', 'head' ]
1010
rails: [ '7.1', 'edge' ]
11+
rubyopt: [""]
1112
include:
12-
- ruby: '2.7'
13-
rails: '6.1'
14-
- ruby: '3.0'
15-
rails: '6.1'
16-
- ruby: '3.1'
17-
rails: '7.0'
13+
- ruby: '3.3'
14+
rails: '7.1'
15+
rubyopt: "--enable-frozen-string-literal"
1816

1917
env:
2018
RAILS_VERSION: ${{ matrix.rails }}
19+
RUBYOPT: ${{ matrix.rubyopt }}
2120

2221
steps:
23-
- uses: actions/checkout@v2
22+
- uses: actions/checkout@v4
2423

2524
- name: Set up Ruby
2625
uses: ruby/setup-ruby@v1
@@ -29,10 +28,10 @@ jobs:
2928
bundler-cache: true
3029

3130
- name: Run unit tests
32-
run: bundle exec rake test:unit
31+
run: bundle exec rake test:unit RUBYOPT="${{ matrix.rubyopt }}"
3332
timeout-minutes: 3
3433

3534
- name: Run acceptance tests
36-
run: bundle exec rake test:acceptance
35+
run: bundle exec rake test:acceptance RUBYOPT="${{ matrix.rubyopt }}"
3736
timeout-minutes: 10
3837
if: ${{ matrix.rails != 'edge' && matrix.ruby != 'head' }} # Acceptance tests use `gem install rails && rails new`

‎lib/spring/json.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# encoding: UTF-8
1+
# frozen_string_literal: true
22

33
# ### WHY SPRING VENDORS A JSON LIBRARY ###
44
#
@@ -13,7 +13,6 @@
1313
module Spring
1414
module JSON
1515
def self.load(string)
16-
string.force_encoding("utf-8")
1716
OkJson.decode(string)
1817
end
1918

@@ -364,7 +363,7 @@ def unquote(q)
364363
end
365364
end
366365
if rubydoesenc?
367-
a[w] = '' << uchar
366+
a[w] = +'' << uchar
368367
w += 1
369368
else
370369
w += ucharenc(a, w, uchar)

‎test/support/acceptance_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ class AcceptanceTest < ActiveSupport::TestCase
1212

1313
def rails_version
1414
if ENV['RAILS_VERSION'] == "edge"
15-
">= 7.1.0.alpha"
15+
">= 8.0.0.alpha"
1616
else
17-
"~> #{ENV['RAILS_VERSION'] || "6.1"}.0"
17+
"~> #{ENV['RAILS_VERSION'] || "7.1"}.0"
1818
end
1919
end
2020

‎test/support/application.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,15 @@ def read_streams
168168
end
169169

170170
def read_stream(stream)
171-
output = ""
171+
output = +""
172172
while IO.select([stream], [], [], 0.5) && !stream.eof?
173173
output << stream.readpartial(10240)
174174
end
175175
output
176176
end
177177

178178
def dump_streams(command, streams)
179-
output = "$ #{command}\n"
179+
output = +"$ #{command}\n"
180180

181181
streams.each do |name, stream|
182182
unless stream.chomp.empty?

‎test/unit/json_test.rb

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require_relative "../helper"
2+
require 'spring/json'
3+
4+
class JsonTest < ActiveSupport::TestCase
5+
test 'can decode unicode characters' do
6+
assert_equal({"unicode_example"=>"©"}, Spring::JSON.load('{"unicode_example": "\u00A9"}'))
7+
end
8+
9+
test 'can encode' do
10+
assert_equal('{}', Spring::JSON.dump({}))
11+
end
12+
end

0 commit comments

Comments
 (0)
Failed to load comments.