[BUG] Empty string id is not correctly validated by forceId

未关闭
#1,519 9 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
javascript, mongodb, node.js
领域
backend, database

调研方向

使用链接的 loopback-sandbox 分支复现该问题,模型配置为 forceId: true,并使用 MongoDB 数据源。跟踪 API 创建路径以及针对显式为空的 id 的 forceId 验证;完成的标准是请求被记录的 422 ValidationError 拒绝,而不是创建数据库条目。

由索引模型根据 Issue 内容生成。

描述

bug good first issue help wanted

Description/Steps to reproduce

  • define a model with forceId: true
  • associate this model to a mongodb data source
  • call the API to create a new model with an explicit empty string id
curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d "{
  \"id\": \"\"
}" "http://localhost:3000/api/foos"
  • this call creates a db entry with empty id and returns: {"id": ""}

Seems related to #1453 (see my comment)

Link to reproduction sandbox

https://github.com/simonbrunel/loopback-sandbox/tree/bug/empty-id-mongodb

Expected result

{
  "error": {
    "name": "ValidationError",
    "status": 422,
    "message": "The `foo` instance is not valid. Details : `id` can't be set (value: \"\").",
    "statusCode": 422,
    "details": {
      "context": "foo",
      "codes": {
        "id": [
          "absence"
        ]
      },
      "messages": {
        "id": [
          "can't be set"
        ]
      }
    }
  }
}

Additional information

node v6.11.3, Windows 10 64bit

npm ls --prod --depth 0 | grep loopback
[email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
主要语言
JavaScript
星标
279
派生
362
平均合并
21 小时 14 分钟
30 天内合并 PR
16

环境准备

从这里开始

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

loopbackio/loopback-datasource-juggler 的其他 Issue

查看 loopbackio/loopback-datasource-juggler 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

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