@@ -10,8 +10,10 @@ const engine: Liquid = new Liquid({
1010engine . filters . set ( 'filename' , posix . basename ) ;
1111engine . filters . set ( 'encode_uri' , encodeURI ) ;
1212engine . filters . set ( 'encode_uri_component' , encodeURIComponent ) ;
13+ engine . filters . set ( 'encode_uri_component_segments' , encodeURIComponentSegments ) ;
1314engine . filters . set ( 'decode_uri' , decodeURI ) ;
1415engine . filters . set ( 'decode_uri_component' , decodeURIComponent ) ;
16+ engine . filters . set ( 'decode_uri_component_segments' , decodeURIComponentSegments ) ;
1517
1618/**
1719 * Parses the given template.
@@ -57,6 +59,29 @@ export function parseTemplate(template: Template | undefined): ParsedTemplate |
5759 } ;
5860}
5961
62+ /**
63+ * A template filter that splits the value into path segments (at the '/' character)
64+ * and applies `encodeURIComponent` on each segment before joining the segments back together.
65+ *
66+ * @param value The value to transform.
67+ * @returns The transformed value.
68+ */
69+ function encodeURIComponentSegments ( value : string ) : string {
70+ // Split the value into path segments so that
71+ // `encodeURIComponent` doesn't encode the '/' character.
72+ return value . split ( '/' ) . map ( encodeURIComponent ) . join ( '/' ) ;
73+ }
74+
75+ /**
76+ * A template filter that reverses `encodeURIComponentSegments`.
77+ *
78+ * @param value The value to transform.
79+ * @returns The transformed value.
80+ */
81+ function decodeURIComponentSegments ( value : string ) : string {
82+ return value . split ( '/' ) . map ( decodeURIComponent ) . join ( '/' ) ;
83+ }
84+
6085/**
6186 * Represents a template that has been pared and can be rendered.
6287 */
0 commit comments