Make parseEnsLabel stricter

This commit is contained in:
Alexis Sellier
2021-07-28 11:23:57 +02:00
parent 3bfb79dd47
commit b585a59163
2 changed files with 6 additions and 9 deletions
+1 -1
View File
@@ -26,7 +26,7 @@
alert("Radicle IDs are not yet supported");
} else {
let label = utils.parseEnsLabel(query, config);
if (label?.includes(".")) {
if (label.includes(".")) {
error = true;
} else {
// Jump straight to org, if the ENS entry points to an org. Otherwise it checks if the
+5 -8
View File
@@ -73,13 +73,11 @@ export function capitalize(s: string): string {
// Takes a domain name, eg. 'cloudhead.radicle.eth' and
// returns the label, eg. 'cloudhead', otherwise `undefined`.
export function parseEnsLabel(name: string | undefined, config: Config): string | undefined {
if (name) {
const domain = config.registrar.domain.replace(".", "\\.");
const label = name.replace(new RegExp(`\\.${domain}$`), "");
export function parseEnsLabel(name: string, config: Config): string {
const domain = config.registrar.domain.replace(".", "\\.");
const label = name.replace(new RegExp(`\\.${domain}$`), "");
return label;
}
return label;
}
// Takes a URL, eg. "https://twitter.com/cloudhead", and return "cloudhead".
@@ -172,8 +170,7 @@ export async function querySubgraph(
// Format a name.
export function formatName(input: string, config: Config): string {
const name = parseEnsLabel(input, config);
return name || input;
return parseEnsLabel(input, config);
}
// Create a Radicle ID from a root hash.