# [Bug]: Inverted assertion arguments in `recent.cljs` and `build.cljs` evaluate the argument instead of the predicate
维护者通常 1 天内回复
评估
调研方向
阅读 src/main/frontend/handler/db_based/recent.cljs 和 deps/db/src/logseq/db/frontend/property/build.cljs,重点查看 add-page-to-recent! 和 build-closed-value-block 中的断言。检查调用方和现有测试如何处理无效 ID,然后验证非数字的 db-id 值和非 UUID 的 block-uuid 值会失败,同时有效值仍能正常工作。
由索引模型根据 Issue 内容生成。
描述
Search first
- I searched and no similar issues were found
What Happened?
Internal type assertions in add-page-to-recent! and build-closed-value-block evaluate the variable as the test condition instead of the predicate. As a result, non-number or non-UUID values (such as strings or keywords) pass through the assertion without error.
Reproduce the Bug
- In a REPL or test, invoke
(frontend.handler.db-based.recent/add-page-to-recent! "not-a-number" false). - Notice that the assertion does not throw an error because
"not-a-number"is truthy in Clojure. - Similarly,
(logseq.db.frontend.property.build/build-closed-value-block "invalid-uuid" ...)passes without error.
Expected Behavior
The assertions should fail if db-id is not a number or block-uuid is not a UUID.
Screenshots
N/A
Desktop or Mobile Platform Information
- OS: All platforms
- App: Logseq Core (master branch)
Additional Context
Root Cause:
In Clojure, assert has signature (assert test-expr [message-expr]).
- In src/main/frontend/handler/db_based/recent.cljs#L7:
(defn add-page-to-recent! [db-id click-from-recent?] (assert db-id (number? db-id)) - In deps/db/src/logseq/db/frontend/property/build.cljs#L27:
(defn build-closed-value-block [block-uuid block-type block-value property {:keys [db-ident icon]}] (assert block-uuid (uuid? block-uuid))
In both locations, the variable was placed in the test position and the predicate was placed in the message position.
Proposed Fix:
;; In recent.cljs:
(assert (number? db-id) "db-id must be a number")
;; In build.cljs:
(assert (uuid? block-uuid) "block-uuid must be a UUID")
Are you willing to submit a PR? If you know how to fix the bug.
- I'm willing to submit a PR (Thank you!)
- 主要语言
- Clojure
- 星标
- 45.7k
- 派生
- 2.9k
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 131
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
logseq/logseq 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 1 天内回复
-
Install script not working可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
logseq/logseq#13638 · 2 个 reaction ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
logseq/logseq#13424 · 2 个 reaction ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
logseq/logseq#12198 · 3 条评论 · 4 个 reaction ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 42/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
clojure-emacs/cider#4235 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
needs triage
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
Server logs every websocket send at DEBUG since #8844, adding lag under load可能已有人在做 @matthewlehew 于 2 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 82/100
维护者通常 1 天内回复