diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 452c12756..11434fb15 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -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 diff --git a/packages/complex-matcher/src/index.js b/packages/complex-matcher/src/index.js index 4f815c10d..84f186075 100644 --- a/packages/complex-matcher/src/index.js +++ b/packages/complex-matcher/src/index.js @@ -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 [] } diff --git a/packages/complex-matcher/src/index.spec.js b/packages/complex-matcher/src/index.spec.js index 3396cc623..1a8d2daf4 100644 --- a/packages/complex-matcher/src/index.spec.js +++ b/packages/complex-matcher/src/index.spec.js @@ -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'], }) }) diff --git a/packages/xo-web/src/xo-app/home/index.js b/packages/xo-web/src/xo-app/home/index.js index 0e88dbcea..b6c9ba8e9 100644 --- a/packages/xo-web/src/xo-app/home/index.js +++ b/packages/xo-web/src/xo-app/home/index.js @@ -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)