check valid name & namespace
This commit is contained in:
parent
f05814570b
commit
e9902febfd
2 changed files with 9 additions and 2 deletions
|
|
@ -71,13 +71,19 @@ export class UI<T extends Type, K extends Renderer | null = null> extends Class
|
|||
) {
|
||||
super()
|
||||
|
||||
if (name === "namespace") {
|
||||
if (name && !/^\p{L}+$/u.test(name)) {
|
||||
throw new Error("Invalid name")
|
||||
} else if (name === "namespace") {
|
||||
console.error("The 'namespace' cannot be used as a name")
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (namespace && !/^\p{L}+$/u.test(namespace)) {
|
||||
throw new Error("Invalid namespace")
|
||||
}
|
||||
|
||||
if (isNotObfuscate || !(allowObfuscate ?? true)) {
|
||||
this.name = name?.match(/^(\w|\/)+/)?.[0] || RandomString(16)
|
||||
this.name = name || RandomString(16)
|
||||
this.namespace = namespace || defaultNamespace || RandomNamespace()
|
||||
} else {
|
||||
this.name = RandomString(16)
|
||||
|
|
|
|||
|
|
@ -154,6 +154,7 @@ export function ResolveBinding(cache: Map<string, unknown>, ...bindings: Binding
|
|||
|
||||
export let defaultNamespace: string | null = null
|
||||
export function SetDefaultNamespace(input: string) {
|
||||
if (!/\p{L}+/u.test(input)) throw new Error("Invalid namespace")
|
||||
defaultNamespace = input
|
||||
}
|
||||
export function ClearDefaultNamespace() {
|
||||
|
|
|
|||
Reference in a new issue