fix: don't recognize emails in quick add magic (#1335)

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/1335
Co-authored-by: konrad <k@knt.li>
Co-committed-by: konrad <k@knt.li>
This commit is contained in:
konrad 2022-01-09 10:17:01 +00:00
parent 76fe2ceac6
commit ed88fb91bc
3 changed files with 21 additions and 6 deletions

View file

@ -13,6 +13,7 @@
"lint": "eslint --ignore-pattern '*.test.*' ./src --ext .vue,.js,.ts",
"cypress:open": "cypress open",
"test:unit": "vitest run",
"test:unit-watch": "vitest watch",
"test:frontend": "cypress run",
"browserslist:update": "npx browserslist@latest --update-db"
},

View file

@ -33,6 +33,13 @@ describe('Parse Task Text', () => {
expect(result.assignees[0]).toBe('user')
})
it('should ignore email addresses', () => {
const text = 'Lorem Ipsum email@example.com'
const result = parseTaskText(text)
expect(result.text).toBe(text)
})
describe('Date Parsing', () => {
it('should not return any date if none was provided', () => {
const result = parseTaskText('Lorem Ipsum')

View file

@ -117,23 +117,30 @@ export const parseTaskText = (text: string, prefixesMode: PrefixMode = PrefixMod
const getItemsFromPrefix = (text: string, prefix: string): string[] => {
const items: string[] = []
const itemParts = text.split(prefix)
const itemParts = text.split(' ' + prefix)
if (text.startsWith(prefix)) {
const firstItem = text.split(prefix)[1]
itemParts.unshift(firstItem)
}
itemParts.forEach((p, index) => {
// First part contains the rest
if (index < 1) {
return
}
let labelText
p = p.replace(prefix, '')
let itemText
if (p.charAt(0) === '\'') {
labelText = p.split('\'')[1]
itemText = p.split('\'')[1]
} else if (p.charAt(0) === '"') {
labelText = p.split('"')[1]
itemText = p.split('"')[1]
} else {
// Only until the next space
labelText = p.split(' ')[0]
itemText = p.split(' ')[0]
}
items.push(labelText)
items.push(itemText)
})
return Array.from(new Set(items))