fix: strip label syntax with parentheses from task title (#1300)

This commit is contained in:
kolaente 2025-08-17 15:05:55 +02:00 committed by GitHub
parent 4144449438
commit fc55563ddd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 6 deletions

View File

@ -650,6 +650,20 @@ describe('Parse Task Text', () => {
expect(result.labels).toHaveLength(1)
expect(result.labels[0]).toBe('today')
})
it('should parse labels with parentheses and remove them from text', () => {
const result = parseTaskText('a *"a (a)"')
expect(result.text).toBe('a')
expect(result.labels).toHaveLength(1)
expect(result.labels[0]).toBe('a (a)')
})
it('should parse labels with parentheses from the start', () => {
const result = parseTaskText('*"a (a)" a')
expect(result.text).toBe('a')
expect(result.labels).toHaveLength(1)
expect(result.labels[0]).toBe('a (a)')
})
})
describe('Project', () => {

View File

@ -276,18 +276,21 @@ const getRepeats = (text: string): repeatParsedResult => {
}
}
const escapeRegExp = (s: string): string => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
export const cleanupItemText = (text: string, items: string[], prefix: string): string => {
items.forEach(l => {
if (l === '') {
return
}
const escaped = escapeRegExp(l)
text = text
.replace(new RegExp(`\\${prefix}'${l}' `, 'ig'), '')
.replace(new RegExp(`\\${prefix}'${l}'`, 'ig'), '')
.replace(new RegExp(`\\${prefix}"${l}" `, 'ig'), '')
.replace(new RegExp(`\\${prefix}"${l}"`, 'ig'), '')
.replace(new RegExp(`\\${prefix}${l} `, 'ig'), '')
.replace(new RegExp(`\\${prefix}${l}`, 'ig'), '')
.replace(new RegExp(`\\${prefix}'${escaped}' `, 'ig'), '')
.replace(new RegExp(`\\${prefix}'${escaped}'`, 'ig'), '')
.replace(new RegExp(`\\${prefix}"${escaped}" `, 'ig'), '')
.replace(new RegExp(`\\${prefix}"${escaped}"`, 'ig'), '')
.replace(new RegExp(`\\${prefix}${escaped} `, 'ig'), '')
.replace(new RegExp(`\\${prefix}${escaped}`, 'ig'), '')
})
return text
}