Merge pull request #1710 from mattermost/plt-1498
PLT-1498 Add hashtag testing and allow special german characters
Этот коммит содержится в:
20
doc/developer/tests/test-hashtags.md
Обычный файл
20
doc/developer/tests/test-hashtags.md
Обычный файл
@@ -0,0 +1,20 @@
|
|||||||
|
# Hashtag Testing
|
||||||
|
|
||||||
|
Hashtags in Mattermosts should render as specified below.
|
||||||
|
|
||||||
|
#### These strings should auto-link:
|
||||||
|
|
||||||
|
#testing
|
||||||
|
#testing123
|
||||||
|
#test-test
|
||||||
|
#test_test
|
||||||
|
#test! (punctuation should be excluded from linking)
|
||||||
|
#test1 #test2
|
||||||
|
#hüllo
|
||||||
|
|
||||||
|
#### These strings should not auto-link:
|
||||||
|
|
||||||
|
#123test
|
||||||
|
#?test
|
||||||
|
#-test
|
||||||
|
|
||||||
@@ -273,9 +273,9 @@ func Etag(parts ...interface{}) string {
|
|||||||
return etag
|
return etag
|
||||||
}
|
}
|
||||||
|
|
||||||
var validHashtag = regexp.MustCompile(`^(#[A-Za-z]+[A-Za-z0-9_\-]*[A-Za-z0-9])$`)
|
var validHashtag = regexp.MustCompile(`^(#[A-Za-zäöüÄÖÜß]+[A-Za-z0-9äöüÄÖÜß_\-]*[A-Za-z0-9äöüÄÖÜß])$`)
|
||||||
var puncStart = regexp.MustCompile(`^[.,()&$!\[\]{}':;\\]+`)
|
var puncStart = regexp.MustCompile(`^[.,()&$!\?\[\]{}':;\\]+`)
|
||||||
var puncEnd = regexp.MustCompile(`[.,()&$#!\[\]{}';\\]+$`)
|
var puncEnd = regexp.MustCompile(`[.,()&$#!\?\[\]{}';\\]+$`)
|
||||||
|
|
||||||
func ParseHashtags(text string) (string, string) {
|
func ParseHashtags(text string) (string, string) {
|
||||||
words := strings.Fields(text)
|
words := strings.Fields(text)
|
||||||
|
|||||||
@@ -81,3 +81,27 @@ func TestEtag(t *testing.T) {
|
|||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var hashtags map[string]string = map[string]string{
|
||||||
|
"#test": "#test",
|
||||||
|
"test": "",
|
||||||
|
"#test123": "#test123",
|
||||||
|
"#123test123": "",
|
||||||
|
"#test-test": "#test-test",
|
||||||
|
"#test?": "#test",
|
||||||
|
"hi #there": "#there",
|
||||||
|
"#bug #idea": "#bug #idea",
|
||||||
|
"#bug or #gif!": "#bug #gif",
|
||||||
|
"#hüllo": "#hüllo",
|
||||||
|
"#?test": "",
|
||||||
|
"#-test": "",
|
||||||
|
"#yo_yo": "#yo_yo",
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseHashtags(t *testing.T) {
|
||||||
|
for input, output := range hashtags {
|
||||||
|
if o, _ := ParseHashtags(input); o != output {
|
||||||
|
t.Fatal("expected=" + output + " actual=" + o)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ function autolinkHashtags(text, tokens) {
|
|||||||
return prefix + alias;
|
return prefix + alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
return output.replace(/(^|\W)(#[a-zA-Z][a-zA-Z0-9.\-_]*)\b/g, replaceHashtagWithToken);
|
return output.replace(/(^|\W)(#[a-zA-ZäöüÄÖÜß][a-zA-Z0-9äöüÄÖÜß.\-_]*)\b/g, replaceHashtagWithToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
const puncStart = /^[.,()&$!\[\]{}':;\\]+/;
|
const puncStart = /^[.,()&$!\[\]{}':;\\]+/;
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user