mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Merge pull request #421 from djreimer/url-encode-filter
Add url_encode standard filter
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
## 3.0.0 / not yet released / branch "master"
|
## 3.0.0 / not yet released / branch "master"
|
||||||
|
|
||||||
* ...
|
* ...
|
||||||
|
* Add url_encode to standard filters, see #421 [Derrick Reimer, djreimer]
|
||||||
* Add uniq to standard filters [Florian Weingarten, fw42]
|
* Add uniq to standard filters [Florian Weingarten, fw42]
|
||||||
* Add exception_handler feature, see #397 and #254 [Bogdan Gusiev, bogdan and Florian Weingarten, fw42]
|
* Add exception_handler feature, see #397 and #254 [Bogdan Gusiev, bogdan and Florian Weingarten, fw42]
|
||||||
* Optimize variable parsing to avoid repeated regex evaluation during template rendering #383 [Jason Hiltz-Laforge, jasonhl]
|
* Optimize variable parsing to avoid repeated regex evaluation during template rendering #383 [Jason Hiltz-Laforge, jasonhl]
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ module Liquid
|
|||||||
input.to_s.gsub(HTML_ESCAPE_ONCE_REGEXP, HTML_ESCAPE)
|
input.to_s.gsub(HTML_ESCAPE_ONCE_REGEXP, HTML_ESCAPE)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def url_encode(input)
|
||||||
|
CGI.escape(input) rescue input
|
||||||
|
end
|
||||||
|
|
||||||
def slice(input, offset, length=nil)
|
def slice(input, offset, length=nil)
|
||||||
offset = Integer(offset)
|
offset = Integer(offset)
|
||||||
length = length ? Integer(length) : 1
|
length = length ? Integer(length) : 1
|
||||||
|
|||||||
@@ -118,6 +118,11 @@ class StandardFiltersTest < Minitest::Test
|
|||||||
assert_equal '<strong>Hulk</strong>', @filters.escape_once('<strong>Hulk</strong>')
|
assert_equal '<strong>Hulk</strong>', @filters.escape_once('<strong>Hulk</strong>')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_url_encode
|
||||||
|
assert_equal 'foo%2B1%40example.com', @filters.url_encode('[email protected]')
|
||||||
|
assert_equal nil, @filters.url_encode(nil)
|
||||||
|
end
|
||||||
|
|
||||||
def test_truncatewords
|
def test_truncatewords
|
||||||
assert_equal 'one two three', @filters.truncatewords('one two three', 4)
|
assert_equal 'one two three', @filters.truncatewords('one two three', 4)
|
||||||
assert_equal 'one two...', @filters.truncatewords('one two three', 2)
|
assert_equal 'one two...', @filters.truncatewords('one two three', 2)
|
||||||
|
|||||||
Reference in New Issue
Block a user