mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 04:40:39 -07:00
fix: remove_last was eating an extra character
This commit is contained in:
@@ -44,7 +44,7 @@ export function remove_last (v: string, l: string) {
|
|||||||
const pattern = String(l)
|
const pattern = String(l)
|
||||||
const index = str.lastIndexOf(pattern)
|
const index = str.lastIndexOf(pattern)
|
||||||
if (index === -1) return str
|
if (index === -1) return str
|
||||||
return str.substring(0, index) + str.substring(index + pattern.length + 1)
|
return str.substring(0, index) + str.substring(index + pattern.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function rstrip (str: string, chars?: string) {
|
export function rstrip (str: string, chars?: string) {
|
||||||
|
|||||||
@@ -203,6 +203,10 @@ describe('filters/string', function () {
|
|||||||
return test('{{ "I strained to see the train through the rain" | remove_last: "rain" }}',
|
return test('{{ "I strained to see the train through the rain" | remove_last: "rain" }}',
|
||||||
'I strained to see the train through the ')
|
'I strained to see the train through the ')
|
||||||
})
|
})
|
||||||
|
it('should remove the last occurrence of substring in the middle of a string', function () {
|
||||||
|
return test('{{ "I strained to see the train through the rain and fog" | remove_last: "rain" }}',
|
||||||
|
'I strained to see the train through the and fog')
|
||||||
|
})
|
||||||
it('should handle substring not found', function () {
|
it('should handle substring not found', function () {
|
||||||
return test('{{ "I strained to see the train through the rain" | remove_last: "no such thing" }}',
|
return test('{{ "I strained to see the train through the rain" | remove_last: "no such thing" }}',
|
||||||
'I strained to see the train through the rain')
|
'I strained to see the train through the rain')
|
||||||
|
|||||||
Reference in New Issue
Block a user