# [Bug]: Inverted assertion arguments in `recent.cljs` and `build.cljs` evaluate the argument instead of the predicate

未关闭 适合新手
#14,044 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@SiddheshP2709 已经在做这个了。

开始于 2026年11月18日。

  • #14054 来自 @SiddheshP2709 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
85/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
clojure
领域
backend

调研方向

阅读 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
  1. In a REPL or test, invoke (frontend.handler.db-based.recent/add-page-to-recent! "not-a-number" false).
  2. Notice that the assertion does not throw an error because "not-a-number" is truthy in Clojure.
  3. 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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

logseq/logseq 的其他 Issue

查看 logseq/logseq 的全部 Issue

相似的 Issue

更多 Clojure Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。