Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Incorrect prototype check

未關閉
#182 2 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
38/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
javascript, node.js
領域
testing

研究方向

使用提供的 Node 範例重現此故障,然後檢查 lib/index.js 第 139 行和第 239 行附近的程式碼,以及 comparePrototypes 設定。當 comparePrototypes 為 false 時,巢狀的 null 原型物件能夠在不發生錯誤的情況下完成比較,即表示完成。

由索引模型根據 Issue 內容生成。

描述

support
Support plan
  • is this issue currently blocking your project? yes
  • is this issue affecting a production system? no
Context
  • node version: 18.x
  • module version with issue: 9.0.3
  • last module version without issue: NA
  • environment (e.g. node, browser, native): node
  • used with @hapi/[email protected]
  • any other relevant information: NA
What are you trying to achieve or the steps to reproduce?

The module does not ignore the prototype during a comparison.

const Code = require('@hapi/code');

const noProto = Object.create(null);
noProto.a = Object.create(null);
noProto.a.b = 1;

Code.settings.comparePrototypes = false;
Code.expect([noProto]).to.once.include({ a: { b: 1 } });

** By using simple objects {} the comparison works as expected.

What was the result you got?
/Users/manuel_spigolon/dev/misc/hapi/code/lib/index.js:139
    throw error;
    ^

Error: Expected [ [Object: null prototype] { a: [Object: null prototype] { b: 1 } } ] to include { a: { b: 1 } } once
    at internals.Assertion.internals.include (/Users/manuel_spigolon/dev/misc/hapi/code/lib/index.js:239:17)
    at Object.<anonymous> (/Users/manuel_spigolon/dev/misc/hapi/code/asd.js:8:32)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:22:47 {
  actual: undefined,
  expected: undefined,
}
What result did you expect?

No error due to the default comparePrototypes = false setting

主要語言
JavaScript
星號
231
分支
75
PR 合併指標
30 天內沒有已合併 PR

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

hapijs/code 的其他 Issue

查看 hapijs/code 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。