From 56c321aeaa75bb3284c67a13a5e61ec450285c34 Mon Sep 17 00:00:00 2001 From: boojack Date: Wed, 26 Jul 2023 21:11:13 +0800 Subject: [PATCH] revert: fix: exclude all punctuation chars except underscore in tags (#2033) Revert "fix: exclude all punctuation chars except underscore in tags (#1974)" This reverts commit 8c6153167181b483d77df726071f844242731711. --- api/v1/tag.go | 2 +- api/v1/tag_test.go | 10 ++-------- web/src/labs/marked/parser/Tag.tsx | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/api/v1/tag.go b/api/v1/tag.go index 3bf6e39f..acd8407b 100644 --- a/api/v1/tag.go +++ b/api/v1/tag.go @@ -176,7 +176,7 @@ func convertTagFromStore(tag *store.Tag) *Tag { } } -var tagRegexp = regexp.MustCompile(`#((?:[^\s\p{P}]|_)+)`) +var tagRegexp = regexp.MustCompile(`#([^\s#,]+)`) func findTagListFromMemoContent(memoContent string) []string { tagMapSet := make(map[string]bool) diff --git a/api/v1/tag_test.go b/api/v1/tag_test.go index 791d83db..10578aab 100644 --- a/api/v1/tag_test.go +++ b/api/v1/tag_test.go @@ -2,8 +2,6 @@ package v1 import ( "testing" - - "golang.org/x/exp/slices" ) func TestFindTagListFromMemoContent(t *testing.T) { @@ -37,16 +35,12 @@ func TestFindTagListFromMemoContent(t *testing.T) { }, { memoContent: "#tag1 http://123123.com?123123#tag2 \n#tag3 #tag4 http://123123.com?123123#tag2) ", - want: []string{"tag1", "tag2", "tag3", "tag4"}, - }, - { - memoContent: "#tag1,#tag2! #tag3.. #tag_4", - want: []string{"tag1", "tag2", "tag3", "tag_4"}, + want: []string{"tag1", "tag2", "tag2)", "tag3", "tag4"}, }, } for _, test := range tests { result := findTagListFromMemoContent(test.memoContent) - if !slices.Equal(result, test.want) { + if len(result) != len(test.want) { t.Errorf("Find tag list %s: got result %v, want %v.", test.memoContent, result, test.want) } } diff --git a/web/src/labs/marked/parser/Tag.tsx b/web/src/labs/marked/parser/Tag.tsx index d7f2b967..95e197a8 100644 --- a/web/src/labs/marked/parser/Tag.tsx +++ b/web/src/labs/marked/parser/Tag.tsx @@ -1,6 +1,6 @@ import { matcher } from "../matcher"; -export const TAG_REG = /#((?:[^\s\p{P}]|_)+)/u; +export const TAG_REG = /#([^\s#,]+)/; const renderer = (rawStr: string) => { const matchResult = matcher(rawStr, TAG_REG);