[PR #7897] [MERGED] fix(game): dungeon map tags and way-out words can't stall on long whitespace #7994

Closed
opened 2026-10-24 04:09:30 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7897
Author: @SpicyMarinara
Created: 10/20/2026
Status: ✅ Merged
Merged: 10/20/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/dungeon-map-redos


📝 Commits (2)

  • cb25a78 fix(game): dungeon map tags and way-out words can't stall on long whitespace
  • a534d34 Merge branch 'staging' into fix/dungeon-map-redos

📊 Changes

2 files changed (+120 additions, -3 deletions)

View changed files

📝 packages/shared/src/features/world/dungeon-map.ts (+13 -3)
➕ scripts/regressions/game-dungeon-tags-redos.regression.ts (+107 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

No issue: this clears CodeQL js/polynomial-redos alerts 634 and 635 (high), which block the v2.5.1 promotion PR #7895.

Why this change

CodeQL flagged two regular expressions in packages/shared/src/features/world/dungeon-map.ts that backtrack polynomially on library input, and those alerts block #7895. The slowdown is real:

  • readGameDungeonTags read the Game Master's [map: ...] tags with /\[map:\s*([^\]]*)\]/giu. A reply with [map: and 50,000 tabs but no ] took about 4.5 s, and 10,000 open [map: took about 1 s. Removing only the \s* would still leave the second case quadratic.
  • dungeonWayOutWords removed a trailing "down"/"up" with /\s+(down|up)$/u. An exit word like "x" + 50,000 spaces + "q" took about 4 s.

What changed

  • readGameDungeonTags finds each [map: with a literal regex (same giu flags) and its first ] with indexOf, then trims the start of the body. It stops when no ] follows, because the old regex could not match any later tag either. Each tag still runs to its first ], and the search resumes after it, as matchAll did. The leave, reveal, name, kind and set rules are unchanged.
  • dungeonWayOutWords removes the trailing down/up with endsWith + trimEnd, only when whitespace comes before it, as the regex did (\s and trimEnd use the same characters).
  • New scripts/regressions/game-dungeon-tags-redos.regression.ts pins outputs for normal input: leave, reveal, name, kind and set tags, mixed case, whitespace and lines inside tags, several tags, nested or unclosed tags, every set's way out in words and as an id, and exit words written by hand. The expected values come from the old code. It also requires adversarial inputs to finish in under 50 ms: [map: + 50,000 tabs, [map: + 50,000 spaces + x, 10,000 open [map:, a closed tag of 50,000 spaces, x + 50,000 spaces + q, and x + 50,000 tabs + up.

Outputs are identical to before. A local differential run compared the new functions with verbatim copies of the old ones on 300,000 random tag texts and 300,000 exit words (Unicode spaces, line separators, BOM, lone surrogates, mixed case), plus every real set. All results matched. The new code finished every adversarial input in under 0.1 ms; the old code took 1–4.5 s.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Agent-run checks on cb25a78fc (boxes left for the human reviewer):

  • pnpm check: passed (format, lint, types and builds).
  • node scripts/run-regressions.mjs --filter passed for game-dungeon-tags-redos (new), game-dungeon-maps, game-map-places and game-overworld-sites: 4/4.
  • The new regression's normal-input expectations also pass against the old staging functions.
  • Local CodeRabbit CLI not run (the release is waiting); GitHub CodeRabbit and CodeQL will review here.

Manual verification notes

  • Manually verify in Game Mode that a Game Master reply with [map: kind="cave" name="Wolf Hollow"] still opens the cave map and [map: leave] still leaves it.
  • Manually verify that the leave button and label still name the way out (for example "the ladder" for a rock cave, "the ladder hatch" for a station).
  • Confirm on this PR's CodeQL run that alerts 634 and 635 no longer appear.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

None: no UI change.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/7897 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/20/2026 **Status:** ✅ Merged **Merged:** 10/20/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/dungeon-map-redos` --- ### 📝 Commits (2) - [`cb25a78`](https://github.com/Pasta-Devs/Marinara-Engine/commit/cb25a78fc598e8add71f940b04c39dd4501fa6fa) fix(game): dungeon map tags and way-out words can't stall on long whitespace - [`a534d34`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a534d348575e04b047249ead2dfbc0ee91891749) Merge branch 'staging' into fix/dungeon-map-redos ### 📊 Changes **2 files changed** (+120 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/shared/src/features/world/dungeon-map.ts` (+13 -3) ➕ `scripts/regressions/game-dungeon-tags-redos.regression.ts` (+107 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue No issue: this clears CodeQL `js/polynomial-redos` alerts **634** and **635** (high), which block the v2.5.1 promotion PR #7895. ## Why this change CodeQL flagged two regular expressions in `packages/shared/src/features/world/dungeon-map.ts` that backtrack polynomially on library input, and those alerts block #7895. The slowdown is real: - `readGameDungeonTags` read the Game Master's `[map: ...]` tags with `/\[map:\s*([^\]]*)\]/giu`. A reply with `[map:` and 50,000 tabs but no `]` took about 4.5 s, and 10,000 open `[map:` took about 1 s. Removing only the `\s*` would still leave the second case quadratic. - `dungeonWayOutWords` removed a trailing "down"/"up" with `/\s+(down|up)$/u`. An exit word like `"x" + 50,000 spaces + "q"` took about 4 s. ## What changed - `readGameDungeonTags` finds each `[map:` with a literal regex (same `giu` flags) and its first `]` with `indexOf`, then trims the start of the body. It stops when no `]` follows, because the old regex could not match any later tag either. Each tag still runs to its first `]`, and the search resumes after it, as `matchAll` did. The leave, reveal, name, kind and set rules are unchanged. - `dungeonWayOutWords` removes the trailing `down`/`up` with `endsWith` + `trimEnd`, only when whitespace comes before it, as the regex did (`\s` and `trimEnd` use the same characters). - New `scripts/regressions/game-dungeon-tags-redos.regression.ts` pins outputs for normal input: leave, reveal, name, kind and set tags, mixed case, whitespace and lines inside tags, several tags, nested or unclosed tags, every set's way out in words and as an id, and exit words written by hand. The expected values come from the old code. It also requires adversarial inputs to finish in under 50 ms: `[map:` + 50,000 tabs, `[map:` + 50,000 spaces + `x`, 10,000 open `[map:`, a closed tag of 50,000 spaces, `x` + 50,000 spaces + `q`, and `x` + 50,000 tabs + `up`. Outputs are identical to before. A local differential run compared the new functions with verbatim copies of the old ones on 300,000 random tag texts and 300,000 exit words (Unicode spaces, line separators, BOM, lone surrogates, mixed case), plus every real set. All results matched. The new code finished every adversarial input in under 0.1 ms; the old code took 1–4.5 s. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` Agent-run checks on `cb25a78fc` (boxes left for the human reviewer): - `pnpm check`: passed (format, lint, types and builds). - `node scripts/run-regressions.mjs --filter` passed for `game-dungeon-tags-redos` (new), `game-dungeon-maps`, `game-map-places` and `game-overworld-sites`: 4/4. - The new regression's normal-input expectations also pass against the old staging functions. - Local CodeRabbit CLI not run (the release is waiting); GitHub CodeRabbit and CodeQL will review here. ### Manual verification notes - Manually verify in Game Mode that a Game Master reply with `[map: kind="cave" name="Wolf Hollow"]` still opens the cave map and `[map: leave]` still leaves it. - Manually verify that the leave button and label still name the way out (for example "the ladder" for a rock cave, "the ladder hatch" for a station). - Confirm on this PR's CodeQL run that alerts 634 and 635 no longer appear. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) None: no UI change. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:09:30 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#7994
No description provided.