From 9e874b518d76624fda3553dd3c341ec5a3147b62 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Thu, 15 Jan 2026 23:57:25 +0100 Subject: [PATCH 1/2] Adapt slice filter to use the correct Array/String index range on TruffleRuby --- lib/liquid/standardfilters.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/liquid/standardfilters.rb b/lib/liquid/standardfilters.rb index 24e135d91..9662c490a 100644 --- a/lib/liquid/standardfilters.rb +++ b/lib/liquid/standardfilters.rb @@ -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 = { '&' => '&', @@ -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 From 9a0f5ddd318ecaaa0dcb62037cdbf2ecb5449064 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Fri, 16 Jan 2026 00:24:42 +0100 Subject: [PATCH 2/2] Add TruffleRuby in CI --- .github/workflows/liquid.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/liquid.yml b/.github/workflows/liquid.yml index c018a4954..1c369e8e3 100644 --- a/.github/workflows/liquid.yml +++ b/.github/workflows/liquid.yml @@ -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 } @@ -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