Skip to content

Commit

Permalink
Fix split filter when input and arg are the same.
Browse files Browse the repository at this point in the history
  • Loading branch information
jg-rp committed Dec 21, 2023
1 parent 0668306 commit ab2f9e0
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Lint
on: [push, pull_request]
jobs:
build:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Tests
on: [push, pull_request]
jobs:
build:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "liquidscript",
"version": "1.8.0",
"version": "1.8.1",
"author": "James",
"license": "MIT",
"homepage": "https://jg-rp.github.io/liquidscript/",
Expand Down
5 changes: 4 additions & 1 deletion src/builtin/filters/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,10 @@ export function split(
subString: unknown,
): string[] | Markup[] {
checkArguments(arguments.length, 1, 1);
return liquidStringify(left).split(liquidStringify(subString));
const val = liquidStringify(left);
const sep = liquidStringify(subString);
if (!val || val === sep) return [];
return val.split(sep);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/lex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
TOKEN_TAG,
} from "./token";

const enum MatchGroup {
enum MatchGroup {
RAW = "raw",
STA = "statement",
RSS = "rightStripStatement",
Expand Down
106 changes: 105 additions & 1 deletion tests/golden/golden_liquid.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.18.0",
"version": "0.20.0",
"test_groups": [
{
"name": "liquid.golden.abs_filter",
Expand Down Expand Up @@ -5655,6 +5655,32 @@
"error": false,
"strict": false
},
{
"name": "quoted, bracketed variable name",
"template": "{{ foo['bar'] }}",
"want": "42",
"context": {
"foo": {
"bar": 42
}
},
"partials": {},
"error": false,
"strict": false
},
{
"name": "quoted, bracketed variable name with whitespace",
"template": "{{ foo['bar baz'] }}",
"want": "42",
"context": {
"foo": {
"bar baz": 42
}
},
"partials": {},
"error": false,
"strict": false
},
{
"name": "render a default given a literal false",
"template": "{{ false | default: 'bar' }}",
Expand Down Expand Up @@ -5833,6 +5859,30 @@
"error": false,
"strict": false
},
{
"name": "top-level quoted, bracketed variable name with whitespace",
"template": "{{ ['bar baz'] }}",
"want": "42",
"context": {
"bar baz": 42
},
"partials": {},
"error": false,
"strict": false
},
{
"name": "top-level quoted, bracketed variable name with whitespace followed by dot notation",
"template": "{{ ['bar baz'].qux }}",
"want": "42",
"context": {
"bar baz": {
"qux": 42
}
},
"partials": {},
"error": false,
"strict": false
},
{
"name": "traverse variables with bracketed identifiers",
"template": "{{ site.data.menu[include.menu][include.locale] }}",
Expand Down Expand Up @@ -7955,6 +8005,15 @@
{
"name": "liquid.golden.split_filter",
"tests": [
{
"name": "argument does not appear in string",
"template": "{% assign a = \"abc\" | split: \",\" %}{% for i in a %}#{{ forloop.index0 }}{{ i }}{% endfor %}",
"want": "#0abc",
"context": {},
"partials": {},
"error": false,
"strict": false
},
{
"name": "argument not a string",
"template": "{{ \"hello th1ere\" | split: 1 | join: \"#\" }}",
Expand All @@ -7964,6 +8023,51 @@
"error": false,
"strict": false
},
{
"name": "empty string and empty argument",
"template": "{% assign a = \"\" | split: \"\" %}{% for i in a %}{{ forloop.index0 }}{{ i }}{% endfor %}",
"want": "",
"context": {},
"partials": {},
"error": false,
"strict": false
},
{
"name": "empty string and single char argument",
"template": "{% assign a = \"\" | split: \",\" %}{% for i in a %}{{ forloop.index0 }}{{ i }}{% endfor %}",
"want": "",
"context": {},
"partials": {},
"error": false,
"strict": false
},
{
"name": "empty string argument",
"template": "{% assign a = \"abc\" | split: \"\" %}{% for i in a %}#{{ forloop.index0 }}{{ i }}{% endfor %}",
"want": "#0a#1b#2c",
"context": {},
"partials": {},
"error": false,
"strict": false
},
{
"name": "left matches argument",
"template": "{% assign a = \",\" | split: \",\" %}{% for i in a %}{{ forloop.index0 }}{{ i }}{% endfor %}",
"want": "",
"context": {},
"partials": {},
"error": false,
"strict": false
},
{
"name": "left matches string repr of argument",
"template": "{% assign a = \"1\" | split: 1 %}{% for i in a %}{{ forloop.index0 }}{{ i }}{% endfor %}",
"want": "",
"context": {},
"partials": {},
"error": false,
"strict": false
},
{
"name": "missing argument",
"template": "{{ \"hello there\" | split }}",
Expand Down

0 comments on commit ab2f9e0

Please sign in to comment.