mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 19:00:39 -07:00
Adapt slice filter to work on non-64 bit platforms
This commit is contained in:
@@ -8,10 +8,19 @@ module Liquid
|
|||||||
MAX_I32 = (1 << 31) - 1
|
MAX_I32 = (1 << 31) - 1
|
||||||
private_constant :MAX_I32
|
private_constant :MAX_I32
|
||||||
|
|
||||||
MIN_I64 = -(1 << 63)
|
supports_64bit_indices = begin
|
||||||
MAX_I64 = (1 << 63) - 1
|
[][1 << 33, 1 << 33]
|
||||||
I64_RANGE = MIN_I64..MAX_I64
|
true
|
||||||
private_constant :MIN_I64, :MAX_I64, :I64_RANGE
|
rescue RangeError
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
INDEX_RANGE = if supports_64bit_indices
|
||||||
|
(-(1 << 63))..((1 << 63) - 1)
|
||||||
|
else
|
||||||
|
(-(1 << 31))..((1 << 31) - 1)
|
||||||
|
end
|
||||||
|
private_constant :INDEX_RANGE
|
||||||
|
|
||||||
HTML_ESCAPE = {
|
HTML_ESCAPE = {
|
||||||
'&' => '&',
|
'&' => '&',
|
||||||
@@ -214,11 +223,11 @@ module Liquid
|
|||||||
Utils.to_s(input).slice(offset, length) || ''
|
Utils.to_s(input).slice(offset, length) || ''
|
||||||
end
|
end
|
||||||
rescue RangeError
|
rescue RangeError
|
||||||
if I64_RANGE.cover?(length) && I64_RANGE.cover?(offset)
|
if INDEX_RANGE.cover?(length) && INDEX_RANGE.cover?(offset)
|
||||||
raise # unexpected error
|
raise # unexpected error
|
||||||
end
|
end
|
||||||
offset = offset.clamp(I64_RANGE)
|
offset = offset.clamp(INDEX_RANGE)
|
||||||
length = length.clamp(I64_RANGE)
|
length = length.clamp(INDEX_RANGE)
|
||||||
retry
|
retry
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user