CodeSampleX

샘플

body-parser 1.20.1: json

검증된 샘플 — npm body-parser 1.20.1: json. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: bodyParser.json() parses application/json objects and…

sha256:d93c607be3a89a2cec677fce3e3dad926337504d1f60e022977d50b0e4e2f178

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-11-21

케이스

HOW
목표
verify body-parser.json in pkg:npm/body-parser@1.20.1
패키지
심벌
  • body-parser.json
환경
node 22.23.2
생성일
2026-11-21T21:13:41Z

컨트랙트

  1. bodyParser.json() parses application/json objects and arrays into req.body with req._body = true, resolves empty bodies (content-length: 0) to {}, rejects whitespace-only payloads with 400 'entity.parse.failed', and leaves pre-parsed requests (req._body = true) unchanged
  2. bodyParser.json() skips requests with no body or a non-matching Content-Type, leaving req._body undefined and req.body as {}
  3. Default strict mode (strict: true) rejects JSON primitives and malformed JSON with a 400 SyntaxError (type 'entity.parse.failed'), while strict: false accepts JSON primitives
  4. Options reviver, limit (413 'entity.too.large'), verify (raw buffer/encoding hook, 403 'entity.verify.failed', TypeError on non-function), inflate (gzip/deflate vs 415 'encoding.unsupported' when false), custom type matchers (string pattern and predicate), and UTF charset enforcement (415 'charset.unsupported') behave as specified

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.js

소스 아티팩트 내려받기 (tar.gz)

소스

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify body-parser.json in pkg:npm/body-parser@1.20.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/body-parser@1.20.1
Demonstrate these symbols/APIs:
  - body-parser.json
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:4fb0ccb4fc2b5d09cbdff7903147b22bc863d9ddf87a1536fdba55b2098ff03e","constraints":{"executionContext":"node"},"contract":["bodyParser.json() parses application/json objects and arrays into req.body with req._body = true, resolves empty bodies (content-length: 0) to {}, rejects whitespace-only payloads with 400 'entity.parse.failed', and leaves pre-parsed requests (req._body = true) unchanged","bodyParser.json() skips requests with no body or a non-matching Content-Type, leaving req._body undefined and req.body as {}","Default strict mode (strict: true) rejects JSON primitives and malformed JSON with a 400 SyntaxError (type 'entity.parse.failed'), while strict: false accepts JSON primitives","Options reviver, limit (413 'entity.too.large'), verify (raw buffer/encoding hook, 403 'entity.verify.failed', TypeError on non-function), inflate (gzip/deflate vs 415 'encoding.unsupported' when false), custom type matchers (string pattern and predicate), and UTF charset enforcement (415 'charset.unsupported') behave as specified"],"goal":"verify body-parser.json in pkg:npm/body-parser@1.20.1","kind":"HOW","packages":["pkg:npm/body-parser@1.20.1"],"schemaVersion":1,"symbols":["body-parser.json"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/body-parser@1.20.1"],"schemaVersion":1,"subject":"pkg:npm/body-parser@1.20.1","symbols":["body-parser.json"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "body-parser-json-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "body-parser-json-sample",
      "version": "1.0.0",
      "dependencies": {
        "body-parser": "1.20.1"
      }
    },
    "node_modules/body-parser": {
      "version": "1.20.1",
      "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz",
      "integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==",
      "license": "MIT",
      "dependencies": {
        "bytes": "3.1.2",
        "content-type": "~1.0.4",
        "debug": "2.6.9",
        "depd": "2.0.0",
        "destroy": "1.2.0",
        "http-errors": "2.0.0",
        "iconv-lite": "0.4.24",
        "on-finished": "2.4.1",
        "qs": "6.11.0",
        "raw-body": "2.5.1",
        "type-is": "~1.6.18",
        "unpipe": "1.0.0"
      },
      "engines": {
        "node": ">= 0.8",
        "npm": "1.2.8000 || >= 1.4.16"
      }
    },
    "node_modules/bytes": {
      "version": "3.1.2",
      "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
      "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.8"
      }
    },
    "node_modules/call-bind-apply-helpers": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
      "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
      "license": "MIT",
      "dependencies": {
        "es-errors": "^1.3.0",
        "function-bind": "^1.1.2"
      },
      "engines": {
        "node": ">= 0.4"
      }
    },
    "node_modules/call-bound": {
      "version": "1.0.4",
      "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz",
      "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
      "license": "MIT",
      "dependencies": {
        "call-bind-apply-helpers": "^1.0.2",
        "get-intrinsic": "^1.3.0"
      },
      "engines": {
        "node": ">= 0.4"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/content-type": {
      "version": "1.0.5",
      "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
      "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.6"
      }
    },
    "node_modules/debug": {
      "version": "2.6.9",
      "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
      "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
      "license": "MIT",
      "dependencies": {
        "ms": "2.0.0"
      }
    },
    "node_modules/depd": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
      "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.8"
      }
    },
    "node_modules/destroy": {
      "version": "1.2.0",
      "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
      "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.8",
        "npm": "1.2.8000 || >= 1.4.16"
      }
    },
    "node_modules/dunder-proto": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
      "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
      "license": "MIT",
      "dependencies": {
        "call-bind-apply-helpers": "^1.0.1",
        "es-errors": "^1.3.0",
        "gopd": "^1.2.0"
      },
      "engines": {
        "node": ">= 0.4"
      }
    },
    "node_modules/ee-first": {
      "version": "1.1.1",
      "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
      "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
      "license": "MIT"
    },
    "node_modules/es-define-property": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
      "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.4"
      }
    },
    "node_modules/es-errors": {
      "version": "1.3.0",
      "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
      "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.4"
      }
    },
    "node_modules/es-object-atoms": {
      "version": "1.1.2",
      "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz",
      "integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==",
      "license": "MIT",
      "dependencies": {
        "es-errors": "^1.3.0"
      },
      "engines": {
        "node": ">= 0.4"
      }
    },
    "node_modules/function-bind": {
      "version": "1.1.2",
      "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
      "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
      "license": "MIT",
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/get-intrinsic": {
      "version": "1.3.0",
      "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
      "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
      "license": "MIT",
      "dependencies": {
        "call-bind-apply-helpers": "^1.0.2",
        "es-define-property": "^1.0.1",
        "es-errors": "^1.3.0",
        "es-object-atoms": "^1.1.1",
        "function-bind": "^1.1.2",
        "get-proto": "^1.0.1",
        "gopd": "^1.2.0",
        "has-symbols": "^1.1.0",
        "hasown": "^2.0.2",
        "math-intrinsics": "^1.1.0"
      },
      "engines": {
        "node": ">= 0.4"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/get-proto": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
      "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
      "license": "MIT",
      "dependencies": {
        "dunder-proto": "^1.0.1",
        "es-object-atoms": "^1.0.0"
      },
      "engines": {
        "node": ">= 0.4"
      }
    },
    "node_modules/gopd": {
      "version": "1.2.0",
      "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
      "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.4"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/has-symbols": {
      "version": "1.1.0",
      "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
      "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.4"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/hasown": {
      "version": "2.0.4",
      "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz",
      "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==",
      "license": "MIT",
      "dependencies": {
        "function-bind": "^1.1.2"
      },
      "engines": {
        "node": ">= 0.4"
      }
    },
    "node_modules/http-errors": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz",
      "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==",
      "license": "MIT",
      "dependencies": {
        "depd": "2.0.0",
        "inherits": "2.0.4",
        "setprototypeof": "1.2.0",
        "statuses": "2.0.1",
        "toidentifier": "1.0.1"
      },
      "engines": {
        "node": ">= 0.8"
      }
    },
    "node_modules/iconv-lite": {
      "version": "0.4.24",
      "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
      "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
      "license": "MIT",
      "dependencies": {
        "safer-buffer": ">= 2.1.2 < 3"
      },
      "engines": {
        "node": ">=0.10.0"
      }
    },
    "node_modules/inherits": {
      "version": "2.0.4",
      "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
      "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
      "license": "ISC"
    },
    "node_modules/math-intrinsics": {
      "version": "1.1.0",
      "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
      "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.4"
      }
    },
    "node_modules/media-typer": {
      "version": "0.3.0",
      "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
      "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.6"
      }
    },
    "node_modules/mime-db": {
      "version": "1.52.0",
      "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
      "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.6"
      }
    },
    "node_modules/mime-types": {
      "version": "2.1.35",
      "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
      "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
      "license": "MIT",
      "dependencies": {
        "mime-db": "1.52.0"
      },
      "engines": {
        "node": ">= 0.6"
      }
    },
    "node_modules/ms": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
      "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
      "license": "MIT"
    },
    "node_modules/object-inspect": {
      "version": "1.14.0",
      "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.14.0.tgz",
      "integrity": "sha512-IVgHNlp/jwQX271+Xzoq9LZNTWXxZK+cEOrGBOBxXNbn7fapnZ+Ts6TVMgNOuAezwG2wdtnMX97tTPK6VEnuOQ==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.4"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/on-finished": {
      "version": "2.4.1",
      "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
      "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
      "license": "MIT",
      "dependencies": {
        "ee-first": "1.1.1"
      },
      "engines": {
        "node": ">= 0.8"
      }
    },
    "node_modules/qs": {
      "version": "6.11.0",
      "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz",
      "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==",
      "license": "BSD-3-Clause",
      "dependencies": {
        "side-channel": "^1.0.4"
      },
      "engines": {
        "node": ">=0.6"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/raw-body": {
      "version": "2.5.1",
      "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz",
      "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==",
      "license": "MIT",
      "dependencies": {
        "bytes": "3.1.2",
        "http-errors": "2.0.0",
        "iconv-lite": "0.4.24",
        "unpipe": "1.0.0"
      },
      "engines": {
        "node": ">= 0.8"
      }
    },
    "node_modules/safer-buffer": {
      "version": "2.1.2",
      "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
      "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
      "license": "MIT"
    },
    "node_modules/setprototypeof": {
      "version": "1.2.0",
      "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
      "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
      "license": "ISC"
    },
    "node_modules/side-channel": {
      "version": "1.1.1",
      "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.1.tgz",
      "integrity": "sha512-6x6dK6zJdpTzF4sQeNYxwtvBzf6Eg4GtlesS94HOvTudUeyK2WXAaIfmDgsyslYrRBeFIlsi54AYsFGUuhmvrQ==",
      "license": "MIT",
      "dependencies": {
        "es-errors": "^1.3.0",
        "object-inspect": "^1.13.4",
        "side-channel-list": "^1.0.1",
        "side-channel-map": "^1.0.1",
        "side-channel-weakmap": "^1.0.2"
      },
      "engines": {
        "node": ">= 0.4"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/side-channel-list": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz",
      "integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==",
      "license": "MIT",
      "dependencies": {
        "es-errors": "^1.3.0",
        "object-inspect": "^1.13.4"
      },
      "engines": {
        "node": ">= 0.4"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/side-channel-map": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz",
      "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==",
      "license": "MIT",
      "dependencies": {
        "call-bound": "^1.0.2",
        "es-errors": "^1.3.0",
        "get-intrinsic": "^1.2.5",
        "object-inspect": "^1.13.3"
      },
      "engines": {
        "node": ">= 0.4"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/side-channel-weakmap": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz",
      "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==",
      "license": "MIT",
      "dependencies": {
        "call-bound": "^1.0.2",
        "es-errors": "^1.3.0",
        "get-intrinsic": "^1.2.5",
        "object-inspect": "^1.13.3",
        "side-channel-map": "^1.0.1"
      },
      "engines": {
        "node": ">= 0.4"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/statuses": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
      "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.8"
      }
    },
    "node_modules/toidentifier": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
      "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
      "license": "MIT",
      "engines": {
        "node": ">=0.6"
      }
    },
    "node_modules/type-is": {
      "version": "1.6.18",
      "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
      "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
      "license": "MIT",
      "dependencies": {
        "media-typer": "0.3.0",
        "mime-types": "~2.1.24"
      },
      "engines": {
        "node": ">= 0.6"
      }
    },
    "node_modules/unpipe": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
      "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.8"
      }
    }
  }
}
package.json
{
  "name": "body-parser-json-sample",
  "version": "1.0.0",
  "private": true,
  "description": "Minimal CommonJS contract sample for body-parser.json in body-parser@1.20.1",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "body-parser": "1.20.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify body-parser.json in pkg:npm/body-parser@1.20.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/body-parser@1.20.1"
  ],
  "symbols": [
    "body-parser.json"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.js
'use strict';

const assert = require('node:assert/strict');
const { PassThrough } = require('node:stream');
const zlib = require('node:zlib');
const bodyParser = require('body-parser');

function invokeJsonMiddleware(middleware, payload, headers = {}, initialReqProps = {}) {
  return new Promise((resolve) => {
    const req = new PassThrough();
    Object.assign(req, initialReqProps);

    const hasPayload = payload !== null && payload !== undefined;
    const buffer = hasPayload
      ? (Buffer.isBuffer(payload) ? payload : Buffer.from(payload, 'utf8'))
      : null;

    req.headers = {
      ...(buffer !== null
        ? {
            'content-type': 'application/json; charset=utf-8',
            'content-length': String(buffer.length),
          }
        : {}),
      ...headers,
    };

    const res = {};
    middleware(req, res, (err) => {
      resolve({ err, req, res });
    });

    if (buffer !== null) {
      req.end(buffer);
    } else {
      req.end();
    }
  });
}

async function main() {
  assert.equal(typeof bodyParser.json, 'function');

  // 1. Default parsing: objects, arrays, whitespace/empty payloads, and already-parsed skip
  {
    const parser = bodyParser.json();

    const obj = await invokeJsonMiddleware(parser, '{"name":"widget","qty":4}');
    assert.equal(obj.err, undefined);
    assert.equal(obj.req._body, true);
    assert.deepEqual(obj.req.body, { name: 'widget', qty: 4 });

    const arr = await invokeJsonMiddleware(parser, '[10, "twenty", true, null]');
    assert.equal(arr.err, undefined);
    assert.equal(arr.req._body, true);
    assert.deepEqual(arr.req.body, [10, 'twenty', true, null]);

    const empty = await invokeJsonMiddleware(parser, '');
    assert.equal(empty.err, undefined);
    assert.equal(empty.req._body, true);
    assert.deepEqual(empty.req.body, {});

    const whitespace = await invokeJsonMiddleware(parser, '   \r\n\t ');
    assert.ok(whitespace.err instanceof SyntaxError);
    assert.equal(whitespace.err.status, 400);
    assert.equal(whitespace.err.type, 'entity.parse.failed');

    const preset = { existing: true };
    const alreadyParsed = await invokeJsonMiddleware(
      parser,
      '{"replaced":true}',
      {},
      { _body: true, body: preset }
    );
    assert.equal(alreadyParsed.err, undefined);
    assert.strictEqual(alreadyParsed.req.body, preset);
  }

  // 2. Skip requests without a body or with non-matching Content-Type
  {
    const parser = bodyParser.json();

    const noBody = await invokeJsonMiddleware(parser, null, {
      'content-type': 'application/json',
    });
    assert.equal(noBody.err, undefined);
    assert.equal(noBody.req._body, undefined);
    assert.deepEqual(noBody.req.body, {});

    const wrongType = await invokeJsonMiddleware(parser, '{"ignored":1}', {
      'content-type': 'text/plain',
    });
    assert.equal(wrongType.err, undefined);
    assert.equal(wrongType.req._body, undefined);
    assert.deepEqual(wrongType.req.body, {});
  }

  // 3. Strict mode (default true) vs strict: false, and malformed JSON
  {
    const strictParser = bodyParser.json();

    for (const primitive of ['"hello"', '123', 'true', 'null']) {
      const rejected = await invokeJsonMiddleware(strictParser, primitive);
      assert.ok(rejected.err instanceof SyntaxError);
      assert.equal(rejected.err.status, 400);
      assert.equal(rejected.err.statusCode, 400);
      assert.equal(rejected.err.type, 'entity.parse.failed');
    }

    const malformed = await invokeJsonMiddleware(strictParser, '{"broken": [1, 2}');
    assert.ok(malformed.err instanceof SyntaxError);
    assert.equal(malformed.err.status, 400);
    assert.equal(malformed.err.type, 'entity.parse.failed');

    const relaxedParser = bodyParser.json({ strict: false });

    const strVal = await invokeJsonMiddleware(relaxedParser, '"hello"');
    assert.equal(strVal.err, undefined);
    assert.equal(strVal.req.body, 'hello');

    const numVal = await invokeJsonMiddleware(relaxedParser, '42');
    assert.equal(numVal.err, undefined);
    assert.equal(numVal.req.body, 42);

    const nullVal = await invokeJsonMiddleware(relaxedParser, 'null');
    assert.equal(nullVal.err, undefined);
    assert.equal(nullVal.req.body, null);
  }

  // 4. reviver and limit options
  {
    const reviverParser = bodyParser.json({
      reviver: (key, value) => (key === 'amount' ? value * 10 : value),
    });
    const revived = await invokeJsonMiddleware(reviverParser, '{"amount":5,"label":"ok"}');
    assert.equal(revived.err, undefined);
    assert.deepEqual(revived.req.body, { amount: 50, label: 'ok' });

    const limitedParser = bodyParser.json({ limit: '16b' });
    const withinLimit = await invokeJsonMiddleware(limitedParser, '{"a":1}');
    assert.equal(withinLimit.err, undefined);
    assert.deepEqual(withinLimit.req.body, { a: 1 });

    const overLimit = await invokeJsonMiddleware(
      limitedParser,
      '{"payload":"exceeds-sixteen-bytes"}'
    );
    assert.ok(overLimit.err);
    assert.equal(overLimit.err.status, 413);
    assert.equal(overLimit.err.type, 'entity.too.large');
  }

  // 5. verify option: raw buffer inspection, rejection with 403, and TypeError validation
  {
    assert.throws(
      () => bodyParser.json({ verify: 123 }),
      { name: 'TypeError', message: 'option verify must be function' }
    );

    let capturedRaw = null;
    let capturedEncoding = null;
    const verifyParser = bodyParser.json({
      verify: (req, _res, buf, encoding) => {
        capturedRaw = buf.toString(encoding);
        capturedEncoding = encoding;
        if (req.headers['x-reject'] === 'yes') {
          throw new Error('signature mismatch');
        }
      },
    });

    const accepted = await invokeJsonMiddleware(verifyParser, '{"verified":true}');
    assert.equal(accepted.err, undefined);
    assert.equal(capturedRaw, '{"verified":true}');
    assert.equal(capturedEncoding, 'utf-8');
    assert.deepEqual(accepted.req.body, { verified: true });

    const rejected = await invokeJsonMiddleware(
      verifyParser,
      '{"verified":false}',
      { 'x-reject': 'yes' }
    );
    assert.ok(rejected.err);
    assert.equal(rejected.err.status, 403);
    assert.equal(rejected.err.type, 'entity.verify.failed');
  }

  // 6. inflate option (gzip/deflate decompression vs 415 when false)
  {
    const rawJson = Buffer.from('{"encoded":"gzip"}', 'utf8');
    const gzipped = zlib.gzipSync(rawJson);

    const inflated = await invokeJsonMiddleware(bodyParser.json(), gzipped, {
      'content-encoding': 'gzip',
    });
    assert.equal(inflated.err, undefined);
    assert.deepEqual(inflated.req.body, { encoded: 'gzip' });

    const deflated = zlib.deflateSync(Buffer.from('{"encoded":"deflate"}', 'utf8'));
    const inflatedDeflate = await invokeJsonMiddleware(bodyParser.json(), deflated, {
      'content-encoding': 'deflate',
    });
    assert.equal(inflatedDeflate.err, undefined);
    assert.deepEqual(inflatedDeflate.req.body, { encoded: 'deflate' });

    const rejectedCompressed = await invokeJsonMiddleware(
      bodyParser.json({ inflate: false }),
      gzipped,
      { 'content-encoding': 'gzip' }
    );
    assert.ok(rejectedCompressed.err);
    assert.equal(rejectedCompressed.err.status, 415);
    assert.equal(rejectedCompressed.err.type, 'encoding.unsupported');
  }

  // 7. Custom type matcher (string pattern and predicate) and charset validation
  {
    const patternParser = bodyParser.json({ type: 'application/*+json' });
    const vndParsed = await invokeJsonMiddleware(patternParser, '{"api":"v1"}', {
      'content-type': 'application/vnd.sample+json',
    });
    assert.equal(vndParsed.err, undefined);
    assert.deepEqual(vndParsed.req.body, { api: 'v1' });

    const predicateParser = bodyParser.json({
      type: (req) => req.headers['x-force-json'] === 'true',
    });
    const forced = await invokeJsonMiddleware(predicateParser, '{"forced":1}', {
      'content-type': 'application/octet-stream',
      'x-force-json': 'true',
    });
    assert.equal(forced.err, undefined);
    assert.deepEqual(forced.req.body, { forced: 1 });

    const badCharset = await invokeJsonMiddleware(bodyParser.json(), '{"a":1}', {
      'content-type': 'application/json; charset=iso-8859-1',
    });
    assert.ok(badCharset.err);
    assert.equal(badCharset.err.status, 415);
    assert.equal(badCharset.err.type, 'charset.unsupported');
  }
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});

오리진 시더

익명