Skip to content

Commit 0a75db3

Browse files
committed
Fix compatibility with --frozen-string-literal
1 parent c5987d5 commit 0a75db3

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,22 @@ jobs:
88
matrix:
99
ruby: [ '3.1', '3.2', '3.3', 'head' ]
1010
rails: [ '7.1', 'edge' ]
11+
rubyopt: [""]
1112
include:
12-
- ruby: '2.7'
13-
rails: '6.1'
1413
- ruby: '3.0'
1514
rails: '6.1'
1615
- ruby: '3.1'
1716
rails: '7.0'
17+
- ruby: '3.3'
18+
rails: '7.1'
19+
rubyopt: "--enable-frozen-string-literal"
1820

1921
env:
2022
RAILS_VERSION: ${{ matrix.rails }}
23+
RUBYOPT: ${{ matrix.rubyopt }}
2124

2225
steps:
23-
- uses: actions/checkout@v2
26+
- uses: actions/checkout@v4
2427

2528
- name: Set up Ruby
2629
uses: ruby/setup-ruby@v1
@@ -29,10 +32,10 @@ jobs:
2932
bundler-cache: true
3033

3134
- name: Run unit tests
32-
run: bundle exec rake test:unit
35+
run: bundle exec rake test:unit RUBYOPT="${{ matrix.rubyopt }}"
3336
timeout-minutes: 3
3437

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

lib/spring/json.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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/application.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ 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

test/unit/json_test.rb

Lines changed: 12 additions & 0 deletions
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)