mirror of
https://github.com/kemko/liquid.git
synced 2026-01-04 17:25:41 +03:00
Compare commits
8 Commits
v5.0.1
...
remove-ext
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be02670a54 | ||
|
|
b1cdd31858 | ||
|
|
8ece160330 | ||
|
|
b9e0d28729 | ||
|
|
020f6b93c5 | ||
|
|
cfe1637bdd | ||
|
|
eab13a07d9 | ||
|
|
ca96ca0fef |
@@ -10,7 +10,7 @@ Performance:
|
|||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
AllCops:
|
AllCops:
|
||||||
TargetRubyVersion: 2.4
|
TargetRubyVersion: 2.5
|
||||||
NewCops: disable
|
NewCops: disable
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'vendor/bundle/**/*'
|
- 'vendor/bundle/**/*'
|
||||||
@@ -18,3 +18,7 @@ AllCops:
|
|||||||
Naming/MethodName:
|
Naming/MethodName:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'example/server/liquid_servlet.rb'
|
- 'example/server/liquid_servlet.rb'
|
||||||
|
|
||||||
|
# Backport https://github.com/Shopify/ruby-style-guide/pull/258
|
||||||
|
Layout/BeginEndAlignment:
|
||||||
|
Enabled: true
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
# Liquid Change Log
|
# Liquid Change Log
|
||||||
|
|
||||||
|
## 5.0.2 (unreleased)
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
* Fix support for using a String subclass for the liquid source (#1421) [Dylan Thacker-Smith]
|
||||||
|
|
||||||
## 5.0.1 / 2021-03-24
|
## 5.0.1 / 2021-03-24
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ require 'bigdecimal'
|
|||||||
|
|
||||||
module Liquid
|
module Liquid
|
||||||
module StandardFilters
|
module StandardFilters
|
||||||
|
MAX_INT = (1 << 31) - 1
|
||||||
HTML_ESCAPE = {
|
HTML_ESCAPE = {
|
||||||
'&' => '&',
|
'&' => '&',
|
||||||
'>' => '>',
|
'>' => '>',
|
||||||
@@ -93,7 +94,13 @@ module Liquid
|
|||||||
words = Utils.to_integer(words)
|
words = Utils.to_integer(words)
|
||||||
words = 1 if words <= 0
|
words = 1 if words <= 0
|
||||||
|
|
||||||
wordlist = input.split(" ", words + 1)
|
wordlist = begin
|
||||||
|
input.split(" ", words + 1)
|
||||||
|
rescue RangeError
|
||||||
|
raise if words + 1 < MAX_INT
|
||||||
|
# e.g. integer #{words} too big to convert to `int'
|
||||||
|
raise Liquid::ArgumentError, "integer #{words} too big for truncatewords"
|
||||||
|
end
|
||||||
return input if wordlist.length <= words
|
return input if wordlist.length <= words
|
||||||
|
|
||||||
wordlist.pop
|
wordlist.pop
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ module Liquid
|
|||||||
attr_reader :line_number, :for_liquid_tag
|
attr_reader :line_number, :for_liquid_tag
|
||||||
|
|
||||||
def initialize(source, line_numbers = false, line_number: nil, for_liquid_tag: false)
|
def initialize(source, line_numbers = false, line_number: nil, for_liquid_tag: false)
|
||||||
@source = source
|
@source = source.to_s.to_str
|
||||||
@line_number = line_number || (line_numbers ? 1 : nil)
|
@line_number = line_number || (line_numbers ? 1 : nil)
|
||||||
@for_liquid_tag = for_liquid_tag
|
@for_liquid_tag = for_liquid_tag
|
||||||
@tokens = tokenize
|
@tokens = tokenize
|
||||||
@@ -24,7 +24,7 @@ module Liquid
|
|||||||
private
|
private
|
||||||
|
|
||||||
def tokenize
|
def tokenize
|
||||||
return [] if @source.to_s.empty?
|
return [] if @source.empty?
|
||||||
|
|
||||||
return @source.split("\n") if @for_liquid_tag
|
return @source.split("\n") if @for_liquid_tag
|
||||||
|
|
||||||
|
|||||||
@@ -2,5 +2,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Liquid
|
module Liquid
|
||||||
VERSION = "5.0.1"
|
VERSION = "5.0.2.alpha"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ module ShopFilter
|
|||||||
end
|
end
|
||||||
|
|
||||||
def script_tag(url)
|
def script_tag(url)
|
||||||
%(<script src="#{url}" type="text/javascript"></script>)
|
%(<script src="#{url}"></script>)
|
||||||
end
|
end
|
||||||
|
|
||||||
def stylesheet_tag(url, media = "all")
|
def stylesheet_tag(url, media = "all")
|
||||||
%(<link href="#{url}" rel="stylesheet" type="text/css" media="#{media}" />)
|
%(<link href="#{url}" rel="stylesheet" #{%(media="#{media}" ) unless media == 'all'}/>)
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_to(link, url, title = "")
|
def link_to(link, url, title = "")
|
||||||
|
|||||||
@@ -178,6 +178,10 @@ class StandardFiltersTest < Minitest::Test
|
|||||||
assert_equal('one two three...', @filters.truncatewords("one two\tthree\nfour", 3))
|
assert_equal('one two three...', @filters.truncatewords("one two\tthree\nfour", 3))
|
||||||
assert_equal('one two...', @filters.truncatewords("one two three four", 2))
|
assert_equal('one two...', @filters.truncatewords("one two three four", 2))
|
||||||
assert_equal('one...', @filters.truncatewords("one two three four", 0))
|
assert_equal('one...', @filters.truncatewords("one two three four", 0))
|
||||||
|
exception = assert_raises(Liquid::ArgumentError) do
|
||||||
|
@filters.truncatewords("one two three four", 1 << 31)
|
||||||
|
end
|
||||||
|
assert_equal("Liquid error: integer #{1 << 31} too big for truncatewords", exception.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_strip_html
|
def test_strip_html
|
||||||
|
|||||||
@@ -323,4 +323,18 @@ class TemplateTest < Minitest::Test
|
|||||||
result = t.render('x' => 1, 'y' => 5)
|
result = t.render('x' => 1, 'y' => 5)
|
||||||
assert_equal('12345', result)
|
assert_equal('12345', result)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_source_string_subclass
|
||||||
|
string_subclass = Class.new(String) do
|
||||||
|
# E.g. ActiveSupport::SafeBuffer does this, so don't just rely on to_s to return a String
|
||||||
|
def to_s
|
||||||
|
self
|
||||||
|
end
|
||||||
|
end
|
||||||
|
source = string_subclass.new("{% assign x = 2 -%} x= {{- x }}")
|
||||||
|
assert_instance_of(string_subclass, source)
|
||||||
|
output = Template.parse(source).render!
|
||||||
|
assert_equal("x=2", output)
|
||||||
|
assert_instance_of(String, output)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user