diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts index 64563ba6b..76a3b1f00 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts @@ -7,6 +7,7 @@ import type { DomainFields, TopLevelDomain } from '@xyo-network/xns-record-paylo import { DomainSchema } from '@xyo-network/xns-record-payload-plugins' import { XnsNamePublicValidators } from '../validation/index.ts' +import { removeDisallowedCharacters } from './lib/index.ts' import type { ValidSourceTypes } from './types/index.ts' export class XnsNameHelper { @@ -90,11 +91,6 @@ export class XnsNameHelper { formattedXnsName = formattedXnsName.replaceAll(/^-+|-+$/g, '') // Filter out disallowed characters. - // NOTE: not necessary because of the regex/replacement above, but leaving for when certain special characters become allowed - for (const reservedCharacter in DisallowedModuleIdentifierCharacters) { - formattedXnsName = formattedXnsName.replaceAll(reservedCharacter, '') - } - - return formattedXnsName + return removeDisallowedCharacters(formattedXnsName) } } diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/index.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/index.ts new file mode 100644 index 000000000..f15734e49 --- /dev/null +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/index.ts @@ -0,0 +1 @@ +export * from './removeDisallowedCharacters.ts' diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/removeDisallowedCharacters.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/removeDisallowedCharacters.ts new file mode 100644 index 000000000..02ea52959 --- /dev/null +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/removeDisallowedCharacters.ts @@ -0,0 +1,18 @@ +import { DisallowedModuleIdentifierCharacters } from '@xyo-network/module-model' + +const DISALLOWED_CHARACTERS = new Set(Object.keys(DisallowedModuleIdentifierCharacters)) + +/** + * Iterates over a string removing disallowed characters + * @param xnsName The XNS name to remove disallowed characters from + * @returns The XNS name with disallowed characters removed + */ +export const removeDisallowedCharacters = (xnsName: string): string => { + let result = '' + for (const char of xnsName) { + if (!DISALLOWED_CHARACTERS.has(char)) { + result += char + } + } + return result +}