Skip to content

[PR] fix: panel blog detail route accepts encoded non-ASCII and dotted slugs - #4961

Closed
ranxianglei wants to merge 14 commits into
masterfrom
2026-10-27_blog-route-encoded-slugs
Closed

ranxianglei wants to merge 14 commits into
masterfrom
2026-10-27_blog-route-encoded-slugs

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #4957

What

Blog ids keep arbitrary filename characters (Chinese, dots, ...) — src/web/blogfeed.ts derives them from filenames with no charset restriction — and the panel index links each card as #/blog/ + encodeURIComponent(id). But route() only matched ^#/blog/([A-Za-z0-9_-]+)$, so every encoded/dotted href failed the match and fell through to the default overview page: clicking such a card landed on overview and the detail page was permanently unreachable.

Fix (one line)

src/web/client.ts: widen the blog capture group to (.+), exactly like the sessions route (^#/sessions(?:/(.+))?$) already does. The existing decodeURIComponent(blg[1]) then restores the original id, and loadBlog exact-matches it against the feed (items.find(x => String(x.id) === String(sub))), degrading to a not-found card on a miss — so the widened pattern cannot surface wrong content or inject anything.

Behavior change

None for currently-working links: ASCII [A-Za-z0-9_-] slugs are a strict subset of .+. Only previously-unreachable hrefs (percent-encoded or dotted ids) now resolve. No config, wire, persistence, or kernel impact — panel client routing only.

Tests

tests/web-blog-route.test.ts: new regression test pins both directions — the index emits the encoded hrefs for a Chinese-id post and a dotted-id article, AND those exact hashes route back to the matching article page (body rendered, back link present, no overview fallback). Verified red before the fix, green after. Existing 4 routing tests + full web-blogfeed.test.ts suite stay green; typecheck + build clean.

Blog ids keep arbitrary filename characters (Chinese, dots, ...) and the
index links them encodeURIComponent'd, but route() only matched
[A-Za-z0-9_-]+ — every such click fell through to overview and the
detail page was unreachable. Widen the capture to (.+) like the
sessions route already does; loadBlog exact-matches the decoded id and
degrades to a not-found card, so nothing new can be injected.

Regression test pins both directions: the index emits the encoded hrefs
AND those exact hashes route back to the matching article page.
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-27_blog-route-encoded-slugs (2acbe81)

Latest build — install this exact version

npm install -g billion-context@0.0.7255-pr.4961.2e7eaa0

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
2acbe81 billion-context@0.0.7255-pr.4961.2e7eaa0 build
7caa777 billion-context@0.0.7153-pr.4961.4de3bf2 build
27c8142 billion-context@0.0.7096-pr.4961.766e6b9 build
b27e78f billion-context@0.0.6880-pr.4961.9143ea0 build
e35ed4f billion-context@0.0.6484-pr.4961.6e6d623 build
33d2ba7 billion-context@0.0.6470-pr.4961.68595c8 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr4961.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: panel blog detail route accepts encoded non-ASCII and dotted slugs [PR] fix: panel blog detail route accepts encoded non-ASCII and dotted slugs Oct 27, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

查重: 不重复(open+closed issue+PR 全检索,blog 路由/详情页方向仅 #4957 + 本 PR 一组;#4915 是 #4906 博客车道的跟踪帖,与本机制无关)。标签: 不新打——bug #4957 已带 bug/scope/ui/p2(详情页局部不可用、有绕行面),PR 镜像帖无需重复。

这是对已完成工作的 PR 审核(分支 2026-10-27_blog-route-encoded-slugs,单 commit 33d2ba7c0,base = 当前 master 头,无冲突)。以下结论是我在分支代码上独立复核的,未沿用 issue 侧已有表述:

方向(审原 issue):问题真实存在,根因定位正确。机制自查复现:索引行 href = "#/blog/" + encodeURIComponent(String(it.id))(src/web/client.ts:940);id 来自文件名且无字符集限制(src/web/blogfeed.ts:263 posts 仅去日期前缀,:312/:457 articles 取 manifest slug 或文件名去 .md)→ 中文/点号 id 的 href 必含 %XX/.;旧正则 ^#/blog/([A-Za-z0-9_-]+)$ 不匹配 → 落默认 overview。修的是路由白名单这一侧(它假设了错误的字符集),不是在编码侧堵症状。✓

回归审查(既有行为逐项):

  • ASCII slug 详情页路由:[A-Za-z0-9_-] ⊂ .+,行为不变(原 4 个路由测试本地重跑全绿);
  • 未知 slug → not-found 卡片:loadBlog 精确匹配(client.ts:910)+ 兜底卡(911–914)未触碰,不变;
  • 裸 #/blog 索引:先被顶层正则命中(client.ts:4317),不走改动行,不变;
  • sessions 路由:未触碰。
  • 披露两处边缘行为漂移(均 p3,应用自身永不产生这类 URL):① 手输非法百分序列如 #/blog/%zzz——旧:落 overview;新:decodeURIComponent 在 hashchange handler 内抛错(页面保持原状+控制台报错)。这与 sessions 路由现状同款(client.ts:4329 同样无守卫),是对齐既有纪律而非新造失败类别,卡片点击路径不可达(encodeURIComponent 恒产出合法序列);② #/blog/<slug>?query——旧:落 overview;新:query 串进捕获组、精确匹配失败 → not-found 卡片。两种结果对这种 URL 形状都算「不对」,量级可忽略。

代码审查:一行正则放宽 + 三行注释说明为什么(引 #4957、点明 exact-match 兜底),与周边风格一致。放宽后无注入面:解码后的 id 只进 String(x.id) === String(sub) 比较,渲染全程 escapeHtml/服务端渲染 markdown(escaped by construction)。✓

测试有效性:新测试用 vm sandbox 驱动真实 WEB_CLIENT(与原 4 测试同一 harness,测的是行为不是 mock),双向钉住:索引对 演示文章/v1.2-notes 确实发出编码 href;这些 href 的精确 hash 再入路由后渲染对应文章正文(zh-body-0/body-1)、blog 区可见、overview 隐藏、back link 在。我本地独立重做了红绿验证:把 client.ts 回退到 master 旧版跑同一测试 → 恰好用例 5 单独红(4/5);恢复修复 → 5/5 绿。非假测试,bug 回归时抓得住。相邻 web-blogfeed.test.ts 8/8 绿。

diff 整洁度:2 文件 +41/-3,单 commit,无跑题文件/空白噪音;测试 harness 仅加一个默认原值的 feed 参数,最小改动。✓

八问:

  1. 是什么问题:博客文章文件名含中文/点号等字符时,面板文章列表点卡片落到总览页,该文章详情页永远打不开。
  2. 什么原因导致的:路由契约两侧失配——列表行按 encodeURIComponent(id) 产出链接(中文变 %XX、点号原样保留),而博客详情正则白名单只放行 [A-Za-z0-9_-],不匹配即落默认 overview。根因在白名单一侧(对 slug 字符集的假设错了),不在编码或 slug 生成。
  3. 影响范围与严重程度:所有文件名带非 ASCII 或点号的 posts/articles(Web Panel Blog: Automatically pulls new posts from GitHub master — no need to wait for a release. | Web 面板博客:自动从 GitHub master 拉取新文章,不用等发版 #4906 把内容源搬到 GitHub master 后此类文件上站即触发;本仓库双语命名,概率实质存在)。当前 master 内容恰好全是 ASCII 文件名,今天未触发。严重度:受影响文章的详情页完全不可用,面板其余功能与代理核心不受影响,p2 局部功能缺陷。
  4. 怎么修复的:捕获组放宽为 (.+),对齐早已在跑的 sessions 路由纪律(宽捕获 + decodeURIComponent + loadBlog 精确 id 匹配 + not-found 兜底)——一行改动,不新造机制。
  5. 是否有回归问题:无(逐项结论见上)。两处手输类边缘漂移已披露(非法百分序列、slug 带 query),均 p3 且与既有 sessions 路由纪律一致,不构成拦下理由。
  6. 是否破坏缓存:不涉及——纯前端 hash 路由,不碰服务端缓存/重试/游标/去重键。
  7. 是否改了设计方向:不涉及——是把博客路由拉齐到仓库既有纪律,不是转向。
  8. 是否引入了新的配置:不涉及。

CI 状态:static-gates×2 / build-artifact / version-guard / test-import-graph / lane-guard / pi-subagents-guard / mysql-contract 及全部 e2e 车道已绿;7 个 test shard 仍 queued/in_progress。

判定:可合。自动合并门槛(§7.4)逐项满足:单模块纯 fix:、回归测试红→绿已独立复证、diff 干净、正文 Closes #4957、不触 kernel/wire/config/persistence/update.ts。合并由 owner 执行;若 test shard 有红我会跟进。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

Review 结论:可合(独立审核,非复读 issue 结论)。

独立验证与回归清点:

  • 方向关:机制复核成立——src/web/client.ts:4323 路由正则 [A-Za-z0-9_-]+ 窄于文件名派生 slug 的实际字符集(src/web/blogfeed.ts:263,slug = 去日期前缀的任意文件名字符),而索引侧链接生成在 client.ts:940 用 encodeURIComponent(String(it.id)) 全量编码。修的方向正确:让路由接受面与链接生成面对齐,而不是把链接生成收窄回 ASCII。
  • 既有行为清单(diff 触碰路径逐项过):① ASCII slug([A-Za-z0-9_-])是 (.+) 的真子集,行为不变;② #/blog/ 空 hash 仍落 overview 路由,不受影响;③ 带 query 的 hash(#/blog/?x=1)本就不匹配、走 not-found 卡,与本 diff 无关(sessions 路由同款 quirk,不在本 PR 范围)。全部保持。
  • 测试有效性:新测双向断言(Test Blind Spot Retrospective: Reinforcing Negative Assertion Discipline, Tightening Fake Upstream Strictness, Thin Inst | 测试盲区复盘:补反向断言纪律、假上游严格化、薄安装冒烟、形态矩阵与生命周期覆盖 #3617 gate 纪律)——索引发出编码 href 且 点进去渲染出对应文章正文+返回链接,harness 参数化未削弱既有断言;bug 回归时该测试会红(正则收回去 → encoded href 不再被路由匹配)。
  • diff 整洁度:两文件,每行都与目的相关,无无关改动。

八问:

  1. 是什么问题:文件名含非 ASCII 或点的博客文章(如 2026-10-27_演示.md),索引上链接生成了,点进去却死在 overview。
  2. 什么原因:路由正则与 slug 实际字符集两侧从未对齐——生成侧全量编码,路由侧只认 [A-Za-z0-9_-]。
  3. 影响范围与严重程度:仅 panel blog tab;此类文件名的文章打不开 = 功能级缺陷,有绕行(重命名文件),p2。
  4. 怎么修复:路由正则放宽为 (.+)(与 sessions 路由 client.ts:4322 一致),附 why 注释说明对齐依据。
  5. 是否有回归:无——见上面三项既有行为清点,全部保持。
  6. 是否破坏缓存:不涉及(纯前端 hash 路由)。
  7. 是否改了设计方向:未改。
  8. 是否引入新配置:无。

CI:head 33d2ba7c0 已跑 lane 全部 success/skipped(33+11),0 failure,余 2 lane 在跑。合并请 owner 操作。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

CI 收尾确认:test 全部 11 个 shard(ubuntu/windows × node 22/24)已 success,其余检查 static-gates×2 / build-artifact / version-guard / test-import-graph / lane-guard / pi-subagents-guard / mysql-contract 全绿,e2e 车道按设计 skipped。整条 CI 无红。

上一条的判定维持:可合,等 owner 合并。

Parallel PR #4969 (same one-line fix, opened later) pinned two extra
shapes this suite did not: a dot + middot + CJK mixed id, and the
not-found degradation for an unknown ENCODED non-ASCII id. Absorb both
so the surviving PR carries the union of coverage; #4969 is marked
duplicate of this branch's PR.
ci-check and others added 12 commits October 30, 2026 01:51
PR #4961 fixes #4957 (panel blog detail route rejecting encoded/dotted slugs):
the identical one-line regex widening ^#/blog/(.+)$ plus equivalent
non-ASCII/dotted-slug regression tests already landed on master via
ca90e44 ('fix: blog detail route rejected non-ASCII slugs ... (#4957)'),
and issue #4957 is closed by that merged fix.

Every conflict resolved in favor of master, so this branch converges to a
no-op superset of master (net-new contribution: none) and can be closed as
duplicate of ca90e44 without importing redundant tests.
…uires (#4599)

The #5140 recovery test proves forkSnapshot reconstructs a non-retained
parent's raw tail from the UNIFIED index — but it never pinned its own
storage mode. Under the CI storage baseline (preload-storage-baseline.mjs
sets BILI_STORAGE_UNIFIED=legacy for the broad corpus) no unified rows
exist, so the reconstruction has no source and forkSnapshot fails closed
with 409 SNAPSHOT_UNAVAILABLE. Deterministic, not a flake: reproduces 100%
on master and any merged branch with BILI_STORAGE_UNIFIED=legacy, passes
without it (default shadow). Pin full like the sibling persist tests and
restore the ambient value afterwards.
ci-fixes at 67f8e89 still leaves four Windows shards red, and all four
deltas already exist on PR #5178. This ports the missing hunks so the
convergence branch actually converges.

1. `test (windows-latest, 2x, 3)` — #5103. `UnifiedShadow` builds its db
   path as `${dir}/index.db`, so the open-failure warning reads
   `C:\...\sessions/index.db`. `issue5103` asserts the warning contains
   `path.join(dir, "index.db")` — `...\index.db` on win32 — so a mixed
   separator never matches. `path` is already imported at :30 and the db is
   opened through the same join, so POSIX output is byte-identical.

2. `test (windows-latest, 22, 4)` + the 4788 leg — #4739/#4788 teardown.
   The suites arm a real `SessionStorage` under
   `BILI_STORAGE_UNIFIED=full`, so the sidecar is still open at teardown.
   `cancelAll()` clears timers and the build map but never closes the
   shadow; Windows refuses to unlink a directory holding an open file
   (`EBUSY`/`EPERM` on `index.db`). Use `closeQuietly()` — cancel, then
   close — in the short-lived-store teardown.

3. `test (ubuntu-latest, 24, 3)` + `(windows-latest, 22, 2)` — #5155.
   Both cold-rebuild cases waited for the debounced durable flush with a
   fixed `setTimeout(20)`. A millisecond budget is a deadline a loaded
   runner can miss, and the miss is an honest `409 !== 200` from a
   one-turn-stale table. Await the settle itself: `afterNextFlush("conv-ptrs")` resolves once the armed save lands.

4. `test (ubuntu-latest, 22, 3)` — #4788 verdict deadlock.
   `afterNextFlush` parks a resolver in `flushWaiters`, and the only thing
   that drains it is the debounce timer — which is armed `unref?.()`.
   Once that timer is the last pending handle the loop drains, the promise
   never settles, and node reports
   `Promise resolution is still pending but the event loop has already
   resolved`. Keep the timer referenced exactly while a waiter exists
   (`ref()` on waiter registration; the host-upkeep default stays unref'd).

Both view hunks and the two test-teardown hunks are byte-identical to the
ones already on PR #5178, so this converges the branches instead of
inventing a third variant.

Verified locally: `npx tsc --noEmit` clean; issue4788 0/4 -> 4/4;
issue4739 4/4; issue5103 5/5; inc-canonical-pointers 3/3.

The `cancelAll` -> `closeQuietly` hunk has no local negative control:
reverting it keeps Linux green because `EBUSY`/`EPERM` only fire where an
open handle blocks unlink. That control can only run on a Windows lane —
stated rather than papered over.

The #4788 arm's own reader is confirmed instead: `cancelAll()` leaves
`index.db`, `index.db-shm`, `index.db-wal` in `/proc/self/fd` while
`closeQuietly()` leaves none (probed directly).
…e settle (#4599)

The turn() helper arms scheduleSave whose debounce timer is unref by design
(persist.ts: a pending save must not hold the process open at shutdown) and
then awaits afterNextFlush. Nothing else in that await is refd, so in a
node:test child whose only surviving handles are unref sockets the event
loop drains before the 50 ms debounce fires and the settle promise never
resolves: all four subtests fail with "Promise resolution is still pending
but the event loop has already resolved" / cancelledByParent. Reproduced
deterministically on master 44067a5 AND on pre-merge ci-fixes 67f8e89
(standalone run, exact CI preload chain), while the same file has passed
some CI legs by ambient-liveness luck - a born-flake per section 7.2
(no environmental luck). The pin at 67f8e89 does not touch this path.

Fix: arm a refd 25 ms keep-alive interval around the afterNextFlush await
(cleared in finally) so the debounce fires deterministically on every host.
Test-only diff; production settle semantics untouched.
…ts ref-tracking fix (#4599)

PR #5262 fixes #4788 at the source: scheduleSave now leaves the debounce
timer refd while flush waiters exist (and afterNextFlush refs a pending
unrefd timer when a waiter registers), so the settle is deterministic for
EVERY caller on every host. The 25 ms keep-alive interval added in
a3019b0 only patched this one test file and is redundant now; removing it
leaves one mechanism instead of two. The comment stays: without it a future
reader re-adds the interval or deletes the persist.ts tracking as dead weight.
@ranxianglei

Copy link
Copy Markdown
Owner Author

Closing: the branch is fully in sync with master — the three-dot diff against origin/master is empty; the blog-detail route slug handling it carries is already on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants