feat(home): use regexp for tags filtering (#4112)
Avoid substring false positives. Fixes #4087
This commit is contained in:
parent
41ca853e03
commit
d82c951db6
@ -3,6 +3,7 @@
|
||||
### Enhancements
|
||||
|
||||
- [Self/New VM] Display confirmation modal when user will use a large amount of resources [#4044](https://github.com/vatesfr/xen-orchestra/issues/4044) (PR [#4127](https://github.com/vatesfr/xen-orchestra/pull/4127))
|
||||
- [Home] No more false positives when select Tag on Home page [#4087](https://github.com/vatesfr/xen-orchestra/issues/4087) (PR [#4112](https://github.com/vatesfr/xen-orchestra/pull/4112))
|
||||
|
||||
### Bug fixes
|
||||
|
||||
@ -10,5 +11,6 @@
|
||||
|
||||
### Released packages
|
||||
|
||||
- complex-matcher v0.6.0
|
||||
- xo-server v5.40.0
|
||||
- xo-web v5.40.0
|
||||
|
@ -599,6 +599,13 @@ export const parse = parser.parse.bind(parser)
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
const _extractStringFromRegexp = child => {
|
||||
const unescapedRegexp = child.re.source.replace(/^(\^)|\\|\$$/g, '')
|
||||
if (child.re.source === `^${escapeRegExp(unescapedRegexp)}$`) {
|
||||
return unescapedRegexp
|
||||
}
|
||||
}
|
||||
|
||||
const _getPropertyClauseStrings = ({ child }) => {
|
||||
if (child instanceof Or) {
|
||||
const strings = []
|
||||
@ -606,6 +613,12 @@ const _getPropertyClauseStrings = ({ child }) => {
|
||||
if (child instanceof StringNode) {
|
||||
strings.push(child.value)
|
||||
}
|
||||
if (child instanceof RegExpNode) {
|
||||
const unescapedRegexp = _extractStringFromRegexp(child)
|
||||
if (unescapedRegexp !== undefined) {
|
||||
strings.push(unescapedRegexp)
|
||||
}
|
||||
}
|
||||
})
|
||||
return strings
|
||||
}
|
||||
@ -613,6 +626,12 @@ const _getPropertyClauseStrings = ({ child }) => {
|
||||
if (child instanceof StringNode) {
|
||||
return [child.value]
|
||||
}
|
||||
if (child instanceof RegExpNode) {
|
||||
const unescapedRegexp = _extractStringFromRegexp(child)
|
||||
if (unescapedRegexp !== undefined) {
|
||||
return [unescapedRegexp]
|
||||
}
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
|
@ -12,10 +12,13 @@ import {
|
||||
} from './'
|
||||
|
||||
it('getPropertyClausesStrings', () => {
|
||||
const tmp = getPropertyClausesStrings(parse('foo bar:baz baz:|(foo bar)'))
|
||||
const tmp = getPropertyClausesStrings(
|
||||
parse('foo bar:baz baz:|(foo bar /^boo$/ /^far$/) foo:/^bar$/')
|
||||
)
|
||||
expect(tmp).toEqual({
|
||||
bar: ['baz'],
|
||||
baz: ['foo', 'bar'],
|
||||
baz: ['foo', 'bar', 'boo', 'far'],
|
||||
foo: ['bar'],
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -20,6 +20,7 @@ import { Card, CardHeader, CardBlock } from 'card'
|
||||
import {
|
||||
ceil,
|
||||
debounce,
|
||||
escapeRegExp,
|
||||
filter,
|
||||
find,
|
||||
forEach,
|
||||
@ -747,7 +748,11 @@ export default class Home extends Component {
|
||||
filter,
|
||||
'tags',
|
||||
new ComplexMatcher.Or(
|
||||
map(tags, tag => new ComplexMatcher.String(tag.id))
|
||||
map(
|
||||
tags,
|
||||
tag =>
|
||||
new ComplexMatcher.RegExp(`^${escapeRegExp(tag.id)}$`)
|
||||
)
|
||||
)
|
||||
)
|
||||
: ComplexMatcher.setPropertyClause(filter, 'tags', undefined)
|
||||
|
Loading…
Reference in New Issue
Block a user