feat: escape filters from Jekyll, #443

This commit is contained in:
Yang Jun
2024-05-12 15:02:04 +08:00
parent 4955e75be7
commit 4561ba3d53
13 changed files with 169 additions and 14 deletions
+3
View File
@@ -33,6 +33,7 @@ filters:
at_most: at_most.html
capitalize: capitalize.html
ceil: ceil.html
cgi_escape: cgi_escape.html
compact: compact.html
concat: concat.html
date: date.html
@@ -93,10 +94,12 @@ filters:
uniq: uniq.html
unshift: unshift.html
upcase: upcase.html
uri_escape: uri_escape.html
url_decode: url_decode.html
url_encode: url_encode.html
where: where.html
where_exp: where_exp.html
xml_escape: xml_escape.html
tags:
overview: overview.html
+17
View File
@@ -0,0 +1,17 @@
---
title: cgi_escape
---
{% since %}v10.13.0{% endsince %}
CGI escape a string for use in a URL. Replaces any special characters with appropriate `%XX` replacements. CGI escape normally replaces a space with a plus `+` sign.
Input
```liquid
{{ "foo, bar; baz?" | cgi_escape }}
```
Output
```text
foo%2C+bar%3B+baz%3F
```
+1 -1
View File
@@ -11,7 +11,7 @@ Categories | Filters
--- | ---
Math | plus, minus, modulo, times, floor, ceil, round, divided_by, abs, at_least, at_most
String | append, prepend, capitalize, upcase, downcase, strip, lstrip, rstrip, strip_newlines, split, replace, replace_first, replace_last,remove, remove_first, remove_last, truncate, truncatewords, normalize_whitespace
HTML/URI | escape, escape_once, url_encode, url_decode, strip_html, newline_to_br
HTML/URI | escape, escape_once, url_encode, url_decode, strip_html, newline_to_br, xml_escape, cgi_escape, uri_escape
Array | slice, map, sort, sort_natural, uniq, where, where_exp, group_by, group_by_exp, find, find_exp, first, last, join, reverse, concat, compact, size, push, pop, shift, unshift
Date | date, date_to_xmlschema, date_to_rfc822, date_to_string, date_to_long_string
Misc | default, json, jsonify, inspect, raw, to_integer
+19
View File
@@ -0,0 +1,19 @@
---
title: uri_escape
---
{% since %}v10.13.0{% endsince %}
Percent encodes any special characters in a URI. URI escape normally replaces a space with `%20`. [Reserved characters][reserved] will not be escaped.
Input
```liquid
{{ "http://foo.com/?q=foo, \bar?" | uri_escape }}
```
Output
```text
http://foo.com/?q=foo,%20%5Cbar?
```
[reserved]: https://en.wikipedia.org/wiki/Percent-encoding#Types_of_URI_characters
+17
View File
@@ -0,0 +1,17 @@
---
title: xml_escape
---
{% since %}v10.13.0{% endsince %}
Escape some text for use in XML.
Input
```liquid
{{ "Have you read \'James & the Giant Peach\'?" | xml_escape }}
```
Output
```text
Have you read 'James & the Giant Peach'?
```
+17
View File
@@ -0,0 +1,17 @@
---
title: cgi_escape
---
{% since %}v10.13.0{% endsince %}
把字符串 CGI 转义,用于 URL。用对应的 `%XX` 替换特殊字符,空格会被转义为 `+` 号。
输入
```liquid
{{ "foo, bar; baz?" | cgi_escape }}
```
输出
```text
foo%2C+bar%3B+baz%3F
```
+1 -1
View File
@@ -11,7 +11,7 @@ LiquidJS 共支持 40+ 个过滤器,可以分为如下几类:
--- | ---
数学 | plus, minus, modulo, times, floor, ceil, round, divided_by, abs, at_least, at_most
字符串 | append, prepend, capitalize, upcase, downcase, strip, lstrip, rstrip, strip_newlines, split, replace, replace_first, replace_last, remove, remove_first, remove_last, truncate, truncatewords, normalize_whitespace
HTML/URI | escape, escape_once, url_encode, url_decode, strip_html, newline_to_br
HTML/URI | escape, escape_once, url_encode, url_decode, strip_html, newline_to_br, xml_escape, cgi_escape, uri_escape
数组 | slice, map, sort, sort_natural, uniq, where, where_exp, group_by, group_by_exp, find, find_exp, first, last, join, reverse, concat, compact, size, push, pop, shift, unshift
日期 | date, date_to_xmlschema, date_to_rfc822, date_to_string, date_to_long_string
其他 | default, json, jsonify, inspect, raw, to_integer
+19
View File
@@ -0,0 +1,19 @@
---
title: uri_escape
---
{% since %}v10.13.0{% endsince %}
把 URI 中的特殊字符做百分号编码,空格会变成 `%20`。[保留字][reserved] 不会被转义。
输入
```liquid
{{ "http://foo.com/?q=foo, \bar?" | uri_escape }}
```
输出
```text
http://foo.com/?q=foo,%20%5Cbar?
```
[reserved]: https://en.wikipedia.org/wiki/Percent-encoding#Types_of_URI_characters
+17
View File
@@ -0,0 +1,17 @@
---
title: xml_escape
---
{% since %}v10.13.0{% endsince %}
把文本做 XML 转义。
输入
```liquid
{{ "Have you read \'James & the Giant Peach\'?" | xml_escape }}
```
输出
```text
Have you read 'James & the Giant Peach'?
```