Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/liquid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
}
- { ruby: 4.0, allowed-failure: false, rubyopt: "--yjit" }
- { ruby: 4.0, allowed-failure: false, rubyopt: "--zjit" }
- { ruby: truffleruby, allowed-failure: false }

# Head can have failures due to being in development
- { ruby: head, allowed-failure: true }
Expand All @@ -44,6 +45,9 @@ jobs:
continue-on-error: ${{ matrix.entry.allowed-failure }}
env:
RUBYOPT: ${{ matrix.entry.rubyopt }}
# TruffleRuby parses methods lazily by default, but we need to hold onto Symbols
# inside methods eagerly for test_does_not_add_drop_methods_to_symbol_table
TRUFFLERUBYOPT: '--experimental-options --lazy-calltargets=false'

spec:
runs-on: ubuntu-latest
Expand Down
16 changes: 9 additions & 7 deletions lib/liquid/standardfilters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ module StandardFilters
MAX_I32 = (1 << 31) - 1
private_constant :MAX_I32

MIN_I64 = -(1 << 63)
MAX_I64 = (1 << 63) - 1
I64_RANGE = MIN_I64..MAX_I64
private_constant :MIN_I64, :MAX_I64, :I64_RANGE
INDEX_RANGE = if RUBY_ENGINE == 'truffleruby'
(-(1 << 31))..((1 << 31) - 1)
else
(-(1 << 63))..((1 << 63) - 1)
end
private_constant :INDEX_RANGE

HTML_ESCAPE = {
'&' => '&amp;',
Expand Down Expand Up @@ -214,11 +216,11 @@ def slice(input, offset, length = nil)
Utils.to_s(input).slice(offset, length) || ''
end
rescue RangeError
if I64_RANGE.cover?(length) && I64_RANGE.cover?(offset)
if INDEX_RANGE.cover?(length) && INDEX_RANGE.cover?(offset)
raise # unexpected error
end
offset = offset.clamp(I64_RANGE)
length = length.clamp(I64_RANGE)
offset = offset.clamp(INDEX_RANGE)
length = length.clamp(INDEX_RANGE)
retry
end
end
Expand Down