fix(filters): replace project titles at the match position, not anywhere in the filter string
continuous-integration/drone/push Build is passing Details

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 #2194
This commit is contained in:
kolaente 2024-03-12 22:05:26 +01:00
parent cf6b476b7d
commit e1c972d64d
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 20 additions and 3 deletions

View File

@ -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',

View File

@ -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)
}
}
})