mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-21 19:26:40 +00:00
[feature] Allow emoji shortcode to be 1-character length (#3556)
* [feature] Allow emoji shortcode to be 1-character length * testerino fixeroni * spaghet
This commit is contained in:
parent
daf55ba6a5
commit
c2029df9bc
|
@ -4920,7 +4920,7 @@ paths:
|
||||||
- description: The code to use for the emoji, which will be used by instance denizens to select it. This must be unique on the instance.
|
- description: The code to use for the emoji, which will be used by instance denizens to select it. This must be unique on the instance.
|
||||||
in: formData
|
in: formData
|
||||||
name: shortcode
|
name: shortcode
|
||||||
pattern: \w{2,30}
|
pattern: \w{1,30}
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
- description: A png or gif image of the emoji. Animated pngs work too! To ensure compatibility with other fedi implementations, emoji size limit is 50kb by default.
|
- description: A png or gif image of the emoji. Animated pngs work too! To ensure compatibility with other fedi implementations, emoji size limit is 50kb by default.
|
||||||
|
@ -5066,7 +5066,7 @@ paths:
|
||||||
- description: The code to use for the emoji, which will be used by instance denizens to select it. This must be unique on the instance. Works for the `copy` action type only.
|
- description: The code to use for the emoji, which will be used by instance denizens to select it. This must be unique on the instance. Works for the `copy` action type only.
|
||||||
in: formData
|
in: formData
|
||||||
name: shortcode
|
name: shortcode
|
||||||
pattern: \w{2,30}
|
pattern: \w{1,30}
|
||||||
type: string
|
type: string
|
||||||
- description: A new png or gif image to use for the emoji. Animated pngs work too! To ensure compatibility with other fedi implementations, emoji size limit is 50kb by default. Works for LOCAL emojis only.
|
- description: A new png or gif image to use for the emoji. Animated pngs work too! To ensure compatibility with other fedi implementations, emoji size limit is 50kb by default. Works for LOCAL emojis only.
|
||||||
in: formData
|
in: formData
|
||||||
|
|
|
@ -53,7 +53,7 @@
|
||||||
// The code to use for the emoji, which will be used by instance denizens to select it.
|
// The code to use for the emoji, which will be used by instance denizens to select it.
|
||||||
// This must be unique on the instance.
|
// This must be unique on the instance.
|
||||||
// type: string
|
// type: string
|
||||||
// pattern: \w{2,30}
|
// pattern: \w{1,30}
|
||||||
// required: true
|
// required: true
|
||||||
// -
|
// -
|
||||||
// name: image
|
// name: image
|
||||||
|
|
|
@ -85,7 +85,7 @@
|
||||||
// The code to use for the emoji, which will be used by instance denizens to select it.
|
// The code to use for the emoji, which will be used by instance denizens to select it.
|
||||||
// This must be unique on the instance. Works for the `copy` action type only.
|
// This must be unique on the instance. Works for the `copy` action type only.
|
||||||
// type: string
|
// type: string
|
||||||
// pattern: \w{2,30}
|
// pattern: \w{1,30}
|
||||||
// -
|
// -
|
||||||
// name: image
|
// name: image
|
||||||
// in: formData
|
// in: formData
|
||||||
|
|
|
@ -560,7 +560,7 @@ func (suite *EmojiUpdateTestSuite) TestEmojiUpdateCopyEmptyShortcode() {
|
||||||
b, err := io.ReadAll(result.Body)
|
b, err := io.ReadAll(result.Body)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
suite.Equal(`{"error":"Bad Request: shortcode did not pass validation, must be between 2 and 30 characters, letters, numbers, and underscores only"}`, string(b))
|
suite.Equal(`{"error":"Bad Request: shortcode did not pass validation, must be between 1 and 30 characters, letters, numbers, and underscores only"}`, string(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *EmojiUpdateTestSuite) TestEmojiUpdateCopyNoShortcode() {
|
func (suite *EmojiUpdateTestSuite) TestEmojiUpdateCopyNoShortcode() {
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
domainGrp = `(?:` + alphaNumeric + `|\.|\-|\:)` // Non-capturing group that matches against a single valid domain character.
|
domainGrp = `(?:` + alphaNumeric + `|\.|\-|\:)` // Non-capturing group that matches against a single valid domain character.
|
||||||
mentionName = `^@(` + usernameGrp + `+)(?:@(` + domainGrp + `+))?$` // Extract parts of one mention, maybe including domain.
|
mentionName = `^@(` + usernameGrp + `+)(?:@(` + domainGrp + `+))?$` // Extract parts of one mention, maybe including domain.
|
||||||
mentionFinder = `(?:^|\s)(@` + usernameGrp + `+(?:@` + domainGrp + `+)?)` // Extract all mentions from a text, each mention may include domain.
|
mentionFinder = `(?:^|\s)(@` + usernameGrp + `+(?:@` + domainGrp + `+)?)` // Extract all mentions from a text, each mention may include domain.
|
||||||
emojiShortcode = `\w{2,30}` // Pattern for emoji shortcodes. maximumEmojiShortcodeLength = 30
|
emojiShortcode = `\w{1,30}` // Pattern for emoji shortcodes. maximumEmojiShortcodeLength = 30
|
||||||
emojiFinder = `(?:\b)?:(` + emojiShortcode + `):(?:\b)?` // Extract all emoji shortcodes from a text.
|
emojiFinder = `(?:\b)?:(` + emojiShortcode + `):(?:\b)?` // Extract all emoji shortcodes from a text.
|
||||||
emojiValidator = `^` + emojiShortcode + `$` // Validate a single emoji shortcode.
|
emojiValidator = `^` + emojiShortcode + `$` // Validate a single emoji shortcode.
|
||||||
usernameStrict = `^[a-z0-9_]{1,64}$` // Pattern for usernames on THIS instance. maximumUsernameLength = 64
|
usernameStrict = `^[a-z0-9_]{1,64}$` // Pattern for usernames on THIS instance. maximumUsernameLength = 64
|
||||||
|
|
|
@ -190,11 +190,11 @@ func CustomCSS(customCSS string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// EmojiShortcode just runs the given shortcode through the regular expression
|
// EmojiShortcode just runs the given shortcode through the regular expression
|
||||||
// for emoji shortcodes, to figure out whether it's a valid shortcode, ie., 2-30 characters,
|
// for emoji shortcodes, to figure out whether it's a valid shortcode, ie., 1-30 characters,
|
||||||
// a-zA-Z, numbers, and underscores.
|
// a-zA-Z, numbers, and underscores.
|
||||||
func EmojiShortcode(shortcode string) error {
|
func EmojiShortcode(shortcode string) error {
|
||||||
if !regexes.EmojiValidator.MatchString(shortcode) {
|
if !regexes.EmojiValidator.MatchString(shortcode) {
|
||||||
return fmt.Errorf("shortcode %s did not pass validation, must be between 2 and 30 characters, letters, numbers, and underscores only", shortcode)
|
return fmt.Errorf("shortcode %s did not pass validation, must be between 1 and 30 characters, letters, numbers, and underscores only", shortcode)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -345,7 +345,7 @@ type testStruct struct {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcode: "p",
|
shortcode: "p",
|
||||||
ok: false,
|
ok: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcode: "pp",
|
shortcode: "pp",
|
||||||
|
@ -361,6 +361,10 @@ type testStruct struct {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcode: "_",
|
shortcode: "_",
|
||||||
|
ok: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
shortcode: "",
|
||||||
ok: false,
|
ok: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -119,7 +119,7 @@ export default function NewEmojiForm() {
|
||||||
label="Shortcode, must be unique among the instance's local emoji"
|
label="Shortcode, must be unique among the instance's local emoji"
|
||||||
autoCapitalize="none"
|
autoCapitalize="none"
|
||||||
spellCheck="false"
|
spellCheck="false"
|
||||||
{...{pattern: "^\\w{2,30}$"}}
|
{...{pattern: "^\\w{1,30}$"}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<CategorySelect
|
<CategorySelect
|
||||||
|
|
|
@ -22,7 +22,7 @@ import { useMemo } from "react";
|
||||||
import { useTextInput } from "../../../../lib/form";
|
import { useTextInput } from "../../../../lib/form";
|
||||||
import { useListEmojiQuery } from "../../../../lib/query/admin/custom-emoji";
|
import { useListEmojiQuery } from "../../../../lib/query/admin/custom-emoji";
|
||||||
|
|
||||||
const shortcodeRegex = /^\w{2,30}$/;
|
const shortcodeRegex = /^\w{1,30}$/;
|
||||||
|
|
||||||
export default function useShortcode() {
|
export default function useShortcode() {
|
||||||
const { data: emoji = [] } = useListEmojiQuery({
|
const { data: emoji = [] } = useListEmojiQuery({
|
||||||
|
@ -42,8 +42,8 @@ export default function useShortcode() {
|
||||||
return "Shortcode already in use";
|
return "Shortcode already in use";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code.length < 2 || code.length > 30) {
|
if (code.length < 1 || code.length > 30) {
|
||||||
return "Shortcode must be between 2 and 30 characters";
|
return "Shortcode must be between 1 and 30 characters";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shortcodeRegex.test(code)) {
|
if (!shortcodeRegex.test(code)) {
|
||||||
|
|
Loading…
Reference in a new issue