diff --git a/client/src/components/Tags/model.test.js b/client/src/components/Tags/model.test.js index ce421e7c0c50..c70736920aeb 100644 --- a/client/src/components/Tags/model.test.js +++ b/client/src/components/Tags/model.test.js @@ -64,13 +64,35 @@ describe("Tags/model.js", () => { describe("Tag matching regular expression tests", () => { it("Should allow valid tags", () => { - const validTags = ["tag1", "tag.subtag", "tag.subtag.subtag", "tag.subtag:value", "🌌", "name:🌌", "🌌.🌌"]; + const validTags = [ + "tag1", + "tag.subtag", + "tag.subtag.subtag", + "tag.subtag:value", + "🌌", + "name:🌌", + "🌌.🌌", + "name:value..separated", + ]; for (const tag of validTags) { expect(VALID_TAG_RE.test(tag)).toBeTruthy(); } }); it("Should not allow invalid tags", () => { - const invalidTags = ["", " ", ".", "..", "...", ":", ":value", "tag:", "tag.", ".tag"]; + const invalidTags = [ + "", + " ", + ".", + "..", + "...", + ":", + ":value", + "tag:", + "tag.", + ".tag", + "tag..subtag:value", + "tag:no spaces in value", + ]; for (const tag of invalidTags) { expect(VALID_TAG_RE.test(tag)).toBeFalsy(); } diff --git a/client/src/components/TagsMultiselect/StatelessTags.vue b/client/src/components/TagsMultiselect/StatelessTags.vue index dfc30060dbb9..7f2256a4aaa3 100644 --- a/client/src/components/TagsMultiselect/StatelessTags.vue +++ b/client/src/components/TagsMultiselect/StatelessTags.vue @@ -7,6 +7,8 @@ import { useToast } from "@/composables/toast"; import { useUid } from "@/composables/utils/uid"; import { useUserTagsStore } from "@/stores/userTagsStore"; +import { VALID_TAG_RE } from "../Tags/model"; + import HeadlessMultiselect from "./HeadlessMultiselect.vue"; import Tag from "./Tag.vue"; @@ -84,10 +86,8 @@ const slicedTags = computed(() => { } }); -const invalidTagRegex = /([.:\s][.:\s])|(^[.:])|([.:]$)|(^[\s]*$)/; - function isValid(tag: string) { - return !tag.match(invalidTagRegex); + return tag.match(VALID_TAG_RE); } function onTagClicked(tag: string) {