Skip to content

Commit

Permalink
Don't allow underscores
Browse files Browse the repository at this point in the history
  • Loading branch information
dcadenas committed Feb 22, 2024
1 parent 203017b commit df02f78
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/nameRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@ export function validateName(name) {
}

if (name.startsWith("-")) {
throw new AppError(422, `Name '${name}' should not start with a hyphen.`);
throw new AppError(422, `Name '${name}' should not start with a hyphen -.`);
}

if (name.endsWith("-")) {
throw new AppError(422, `Name '${name}' should not start with a hyphen.`);
throw new AppError(422, `Name '${name}' should not start with a hyphen -.`);
}

if (name.includes("_")) {
throw new AppError(
422,
`Name '${name}' should not include an underscore _.`
);
}
}
11 changes: 11 additions & 0 deletions test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ describe("Nostr NIP 05 API tests", () => {
.expect(422);
});

it("should fail if the name includes an underscore", async () => {
const userData = createUserData({ name: "aa_" });

await request(app)
.post("/api/names")
.set("Host", "nos.social")
.set("Authorization", `Nostr ${nip98PostAuthToken}`)
.send(userData)
.expect(422);
});

it("should fail if the name is not found", async () => {
await request(app)
.get("/.well-known/nostr.json")
Expand Down

0 comments on commit df02f78

Please sign in to comment.