-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
split
filter compatibility issues (#135)
* Add failing `split` filter test cases. See #134. * Add compatible implementation of `split`. * Fix left matches repr of argument. * Simplify by combining condition. * Add more to doc comment. * Update change log and bump version number.
- Loading branch information
Showing
6 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from ._split import split # noqa: D104 | ||
|
||
__all__ = ("split",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""An implementation of the `split` filter.""" | ||
|
||
from typing import List | ||
|
||
from liquid import soft_str | ||
from liquid.filter import string_filter | ||
|
||
|
||
@string_filter | ||
def split(val: str, sep: str) -> List[str]: | ||
"""Split string _val_ on delimiter _sep_. | ||
If _sep_ is empty or _undefined_, _val_ is split into a list of single | ||
characters. If _val_ is empty or equal to _sep_, an empty list is returned. | ||
""" | ||
if not sep: | ||
return list(val) | ||
|
||
sep = soft_str(sep) | ||
if not val or val == sep: | ||
return [] | ||
|
||
return val.split(sep) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters