Public: anyone can read this; the crew can change it.

f2f: world names up to 32 characters #9

Closed opened this From outside
Closed without merging

f2f-maker/voxel:maker/main → main 2 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
5 files changed +14 −9
src/pages/home.ts +3 −3
@@ -5,7 +5,7 @@
55 */
66
77 import { escape, head, where, commit } from "./layout.ts";
8 import { NAME_PATTERN } from "../valid.ts";
8 import { NAME_MAX, NAME_PATTERN } from "../valid.ts";
99 import type { World } from "../db.ts";
1010
1111 const STYLE = `
@@ -57,7 +57,7 @@ function deleteForm(name: string, mine: boolean): string {
5757 return `<details class="drop"><summary>delete</summary><div>
5858 <p>You did not make ${escape(name)}. Type its name to delete it and everything in it.</p>
5959 <form method="post" action="/worlds/delete">${hidden}
60 <input class="confirm" name="confirm" maxlength="24" placeholder="${escape(name)}"
60 <input class="confirm" name="confirm" maxlength="${NAME_MAX}" placeholder="${escape(name)}"
6161 aria-label="Type the world's name to confirm" required>
6262 <button class="quiet">delete</button>
6363 </form>
@@ -87,7 +87,7 @@ export function homePage(
8787 ${commit ? `<code>${escape(commit)}</code>` : ""}</p>
8888
8989 <form class="new" method="post" action="/worlds">
90 <input name="name" placeholder="World name" required maxlength="24" pattern="${NAME_PATTERN}"
90 <input name="name" placeholder="World name" required maxlength="${NAME_MAX}" pattern="${NAME_PATTERN}"
9191 title="Letters, digits, spaces, dashes and underscores" autofocus>
9292 <input name="seed" placeholder="Seed (optional)" maxlength="32">
9393 <button>Make a world</button>
src/server.test.ts +4 −1
@@ -49,6 +49,7 @@ test("the front page lists worlds and hands out a session", async () => {
4949 const body = await response.text();
5050 expect(body).toContain("<h1>voxel</h1>");
5151 expect(body).toContain("No worlds yet");
52 expect(body).toContain(`maxlength="32" pattern="[A-Za-z0-9][A-Za-z0-9 _-]{0,31}"`);
5253 });
5354
5455 test("every response stands on the security floor", async () => {
@@ -333,7 +334,9 @@ test("names, seeds and edits are checked before anything else sees them", () =>
333334 expect(worldName("hi/there")).toBeNull();
334335 expect(worldName("")).toBeNull();
335336 expect(worldName("<script>")).toBeNull();
336 expect(worldName("a".repeat(25))).toBeNull();
337 expect(worldName("Saturday building session 01")).toBe("Saturday building session 01");
338 expect(worldName("a".repeat(32))).toBe("a".repeat(32));
339 expect(worldName("a".repeat(33))).toBeNull();
337340 expect(worldName(42)).toBeNull();
338341 expect(seedFrom("1234")).toBe(1234);
339342 expect(seedFrom("hello")).toBe(seedFrom("hello"));
src/server.ts +2 −2
@@ -11,7 +11,7 @@ import { Buckets } from "./bucket.ts";
1111 import { buildClient } from "./bundle.ts";
1212 import { gamePage } from "./pages/game.ts";
1313 import { homePage } from "./pages/home.ts";
14 import { editsFrom, playerFrom, seedFrom, worldName } from "./valid.ts";
14 import { NAME_MAX, editsFrom, playerFrom, seedFrom, worldName } from "./valid.ts";
1515 import { HOTBAR } from "./world/blocks.ts";
1616 import { findSpawn } from "./world/terrain.ts";
1717
@@ -221,7 +221,7 @@ export const server = Bun.serve({
221221 if (form === OVER) return tooBig(cookie);
222222 const name = form && worldName(form.get("name"));
223223 if (!name) {
224 return page("no", `<p>A world's name is 1 to 24 letters, digits, spaces, dashes or underscores.
224 return page("no", `<p>A world's name is 1 to ${NAME_MAX} letters, digits, spaces, dashes or underscores.
225225 <a href="/">Try again.</a></p>`, 400, cookie);
226226 }
227227 let world = store.world(name);
src/tty.ts +2 −2
@@ -19,7 +19,7 @@ import { findSpawn } from "./world/terrain.ts";
1919 import { DAY_SECONDS, daylight, timeName } from "./world/daylight.ts";
2020 import { Herd } from "./world/herd.ts";
2121 import { KINDS } from "./world/mobs.ts";
22 import { seedFrom, worldName } from "./valid.ts";
22 import { NAME_MAX, seedFrom, worldName } from "./valid.ts";
2323
2424 const store = new Store(open());
2525 const where = process.env.FORGE_APP_ENV === "preview"
@@ -224,7 +224,7 @@ process.stdin.on("data", (key: string) => {
224224 prompt = undefined;
225225 } else if (key === "\x1b") { prompt = undefined; says = ""; }
226226 else if (key === "\x7f") prompt = { ...prompt, text: prompt.text.slice(0, -1) };
227 else if (key >= " " && prompt.text.length < 24) prompt = { ...prompt, text: prompt.text + key };
227 else if (key >= " " && prompt.text.length < NAME_MAX) prompt = { ...prompt, text: prompt.text + key };
228228 draw();
229229 return;
230230 }
src/valid.ts +3 −1
@@ -9,7 +9,9 @@ import { isBlockId } from "./world/blocks.ts";
99 import { hash3 } from "./world/noise.ts";
1010 import type { Edit, Player } from "./db.ts";
1111
12 export const NAME_PATTERN = "[A-Za-z0-9][A-Za-z0-9 _-]{0,23}";
12 /** The longest a world's name may be, in characters. */
13 export const NAME_MAX = 32;
14 export const NAME_PATTERN = `[A-Za-z0-9][A-Za-z0-9 _-]{0,${NAME_MAX - 1}}`;
1315 const NAME = new RegExp(`^${NAME_PATTERN}$`);
1416 /** Blocks can be placed this far from the origin, in either direction. */
1517 export const WORLD_LIMIT = 1_000_000;

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs