fix(filters): replace project titles at the match position, not anywhere in the filter string
This fixes a bug where the project title would not be replaced correctly in cases where the project title contained parts of the word "project". Resolves https://kolaente.dev/vikunja/vikunja/issues/2194
This commit is contained in:
parent
cf6b476b7d
commit
e1c972d64d
@ -18,7 +18,7 @@ describe('Filter Transformation', () => {
|
||||
'labels': 'labels',
|
||||
}
|
||||
|
||||
describe('For api', () => {
|
||||
describe('For API', () => {
|
||||
for (const c in fieldCases) {
|
||||
it('should transform all filter params for ' + c + ' to snake_case', () => {
|
||||
const transformed = transformFilterStringForApi(c + ' = ipsum', nullTitleToIdResolver, nullTitleToIdResolver)
|
||||
@ -97,6 +97,16 @@ describe('Filter Transformation', () => {
|
||||
|
||||
expect(transformed).toBe('project in 1, 2')
|
||||
})
|
||||
|
||||
it('should resolve projects at the correct position', () => {
|
||||
const transformed = transformFilterStringForApi(
|
||||
'project = pr',
|
||||
nullTitleToIdResolver,
|
||||
(title: string) => 1,
|
||||
)
|
||||
|
||||
expect(transformed).toBe('project = 1')
|
||||
})
|
||||
})
|
||||
|
||||
describe('To API', () => {
|
||||
@ -138,7 +148,7 @@ describe('Filter Transformation', () => {
|
||||
|
||||
expect(transformed).toBe('labels = lorem && dueDate = now && labels = ipsum')
|
||||
})
|
||||
|
||||
|
||||
it('should correctly resolve multiple labels in', () => {
|
||||
const transformed = transformFilterStringFromApi(
|
||||
'labels in 1, 2',
|
||||
|
@ -108,12 +108,19 @@ export function transformFilterStringForApi(
|
||||
keywords = keyword.trim().split(',').map(k => k.trim())
|
||||
}
|
||||
|
||||
let replaced = keyword
|
||||
|
||||
keywords.forEach(k => {
|
||||
const projectId = projectResolver(k)
|
||||
if (projectId !== null) {
|
||||
filter = filter.replace(k, String(projectId))
|
||||
replaced = replaced.replace(k, String(projectId))
|
||||
}
|
||||
})
|
||||
|
||||
const actualKeywordStart = (match?.index || 0) + prefix.length
|
||||
filter = filter.substring(0, actualKeywordStart) +
|
||||
replaced +
|
||||
filter.substring(actualKeywordStart + keyword.length)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user