1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-03 17:59:37 +02:00

fix: plugin/theme names with scope are not allowed

This commit is contained in:
Sébastien NOBILI 2025-02-11 16:08:52 +01:00 committed by Chocobozzz
parent 6e296350e4
commit 8426746bf1

View file

@ -6,6 +6,10 @@ import { exists, isArray, isSafePath } from './misc.js'
const PLUGINS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.PLUGINS
const NPM_VALIDATION_RE = new RegExp(
/^(@[^\._][a-z-_\.~0-9]+\/)?([a-z-0-9]+)$/,
);
function isPluginTypeValid (value: any) {
return exists(value) &&
(value === PluginType.PLUGIN || value === PluginType.THEME)
@ -14,14 +18,16 @@ function isPluginTypeValid (value: any) {
function isPluginNameValid (value: string) {
return exists(value) &&
validator.default.isLength(value, PLUGINS_CONSTRAINTS_FIELDS.NAME) &&
validator.default.matches(value, /^[a-z-0-9]+$/)
validator.default.matches(value, NPM_VALIDATION_RE)
}
function isNpmPluginNameValid (value: string) {
const match = value.match(NPM_VALIDATION_RE);
return exists(value) &&
validator.default.isLength(value, PLUGINS_CONSTRAINTS_FIELDS.NAME) &&
validator.default.matches(value, /^[a-z\-._0-9]+$/) &&
(value.startsWith('peertube-plugin-') || value.startsWith('peertube-theme-'))
validator.default.matches(value, NPM_VALIDATION_RE) &&
(match[2].startsWith("peertube-plugin-") ||
match[2].startsWith("peertube-theme-"))
}
function isPluginDescriptionValid (value: string) {