Skip to content

Commit

Permalink
Merge pull request #19166 from dannon/tag-validation-fix
Browse files Browse the repository at this point in the history
Consolidate tag validation
  • Loading branch information
dannon authored Nov 20, 2024
2 parents a7afb68 + 8109f78 commit de87409
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
26 changes: 24 additions & 2 deletions client/src/components/Tags/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/TagsMultiselect/StatelessTags.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit de87409

Please sign in to comment.