mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
fix: contains regression (#677)
* fix: `contains` regression on string-like objects, #675 * chore: fix build docs on macos
This commit is contained in:
+3
-12
@@ -1,17 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Run `sed` in a way that's compatible with both macOS (BSD) and Linux (GNU)
|
|
||||||
sedi() {
|
|
||||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
||||||
sed -i '' "$@"
|
|
||||||
else
|
|
||||||
sed -i "$@"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
cd docs
|
cd docs
|
||||||
cp ../CHANGELOG.md source/tutorials/changelog.md
|
cp ../CHANGELOG.md source/tutorials/changelog.md
|
||||||
sedi \
|
sed -i \
|
||||||
-e 's/{%/{% raw %}{%{% endraw %}/g' \
|
-e 's/{%/{% raw %}{%{% endraw %}/g' \
|
||||||
-e 's/{{/{% raw %}{{{% endraw %}/g' \
|
-e 's/{{/{% raw %}{{{% endraw %}/g' \
|
||||||
-e '1 s/"/\"/g' \
|
-e '1 s/"/\"/g' \
|
||||||
@@ -20,7 +11,7 @@ sedi \
|
|||||||
source/tutorials/changelog.md
|
source/tutorials/changelog.md
|
||||||
cp source/tutorials/changelog.md source/zh-cn/tutorials/changelog.md
|
cp source/tutorials/changelog.md source/zh-cn/tutorials/changelog.md
|
||||||
|
|
||||||
sedi -e '1i\
|
sed -i -e '1i\
|
||||||
---\ntitle: Changelog\nauto: true\n---\n' source/tutorials/changelog.md
|
---\ntitle: Changelog\nauto: true\n---\n' source/tutorials/changelog.md
|
||||||
sedi -e '1i\
|
sed -i -e '1i\
|
||||||
---\ntitle: 更新日志\nauto: true\n---\n' source/zh-cn/tutorials/changelog.md
|
---\ntitle: 更新日志\nauto: true\n---\n' source/zh-cn/tutorials/changelog.md
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { isComparable } from '../drop/comparable'
|
|||||||
import { Context } from '../context'
|
import { Context } from '../context'
|
||||||
import { toValue } from '../util'
|
import { toValue } from '../util'
|
||||||
import { isFalsy, isTruthy } from '../render/boolean'
|
import { isFalsy, isTruthy } from '../render/boolean'
|
||||||
import { isArray, isString } from '../util/underscore'
|
import { isArray, isFunction } from '../util/underscore'
|
||||||
|
|
||||||
export type UnaryOperatorHandler = (operand: any, ctx: Context) => boolean;
|
export type UnaryOperatorHandler = (operand: any, ctx: Context) => boolean;
|
||||||
export type BinaryOperatorHandler = (lhs: any, rhs: any, ctx: Context) => boolean;
|
export type BinaryOperatorHandler = (lhs: any, rhs: any, ctx: Context) => boolean;
|
||||||
@@ -35,7 +35,7 @@ export const defaultOperators: Operators = {
|
|||||||
'contains': (l: any, r: any) => {
|
'contains': (l: any, r: any) => {
|
||||||
l = toValue(l)
|
l = toValue(l)
|
||||||
if (isArray(l)) return l.some((i) => equal(i, r))
|
if (isArray(l)) return l.some((i) => equal(i, r))
|
||||||
if (isString(l)) return l.indexOf(toValue(r)) > -1
|
if (isFunction(l?.indexOf)) return l.indexOf(toValue(r)) > -1
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
'not': (v: any, ctx: Context) => isFalsy(toValue(v), ctx),
|
'not': (v: any, ctx: Context) => isFalsy(toValue(v), ctx),
|
||||||
|
|||||||
@@ -485,4 +485,18 @@ describe('Issues', function () {
|
|||||||
'{% endif %}', {})
|
'{% endif %}', {})
|
||||||
expect(result).toEqual('show')
|
expect(result).toEqual('show')
|
||||||
})
|
})
|
||||||
|
it('#675 10.10.1 Operator: contains regression', () => {
|
||||||
|
const engine = new Liquid()
|
||||||
|
class StrictStringForLiquid {
|
||||||
|
constructor (private value: string) {}
|
||||||
|
indexOf (other: unknown) {
|
||||||
|
return this.value.indexOf(String(other))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const result = engine.parseAndRenderSync('{{ str contains sub }}', {
|
||||||
|
str: new StrictStringForLiquid('string'),
|
||||||
|
sub: 'str'
|
||||||
|
})
|
||||||
|
expect(result).toEqual('true')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user