diff options
author | 2024-02-20 11:46:04 +0100 | |
---|---|---|
committer | 2024-02-20 11:46:04 +0100 | |
commit | 65a273bc39bd2e278911d0787278e512f4013910 (patch) | |
tree | 2f42dc1f2d0d5d9bf4c147d39cd759f8c1a5df9d /internal/validate/formvalidation_test.go | |
parent | [chore/frontend] Use different background color for block quotes (#2668) (diff) | |
download | gotosocial-65a273bc39bd2e278911d0787278e512f4013910.tar.xz |
[bugfix] use start + end line in regex when validating emoji via API (#2671)
Diffstat (limited to 'internal/validate/formvalidation_test.go')
-rw-r--r-- | internal/validate/formvalidation_test.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/internal/validate/formvalidation_test.go b/internal/validate/formvalidation_test.go index 40830407c..578b300ea 100644 --- a/internal/validate/formvalidation_test.go +++ b/internal/validate/formvalidation_test.go @@ -321,6 +321,63 @@ func (suite *ValidationTestSuite) TestValidateCustomCSSTooLongUnicode() { suite.EqualError(err, "custom_css must be less than 5 characters, but submitted custom_css was 10 characters") } +func (suite *ValidationTestSuite) TestValidateEmojiShortcode() { + type testStruct struct { + shortcode string + ok bool + } + + for _, test := range []testStruct{ + { + shortcode: "peepee", + ok: true, + }, + { + shortcode: "poo-poo", + ok: false, + }, + { + shortcode: "-peepee", + ok: false, + }, + { + shortcode: "p", + ok: false, + }, + { + shortcode: "pp", + ok: true, + }, + { + shortcode: "6969", + ok: true, + }, + { + shortcode: "__peepee", + ok: true, + }, + { + shortcode: "_", + ok: false, + }, + { + // Too long. + shortcode: "_XxX_Ultimate_Gamer_dude_6969_420_", + ok: false, + }, + { + shortcode: "_XxX_Ultimate_Gamer_dude_6969_", + ok: true, + }, + } { + err := validate.EmojiShortcode(test.shortcode) + ok := err == nil + if !suite.Equal(test.ok, ok) { + suite.T().Logf("fail on %s", test.shortcode) + } + } +} + func TestValidationTestSuite(t *testing.T) { suite.Run(t, new(ValidationTestSuite)) } |