Decide how invalid options are handled in the next major

Đang mở
#775 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
28/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Sôi nổi
Lĩnh vực
backend

Hướng nghiên cứu

Start by reading normalizeOptions and the json(), urlencoded(), and text() parser entry points to compare how each option is validated. Review the reported defaultCharset cases and the related change in #764. Done means a policy for invalid options has been selected, consistently implemented across parsers, and covered by tests, including case-insensitive charset handling.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

semver-major

@Phillip9587 suggested an issue for this in #764. Measured on master (02101da) with Node 26; the Express results use Express 5.3.0.

normalizeOptions, one option at a time:

option 42 false 0 '' {}
inflate true false true true true
limit 42 throws 0 throws throws
verify throws false false false throws
defaultCharset 42 'utf-8' 'utf-8' 'utf-8' {}

type: 42 is accepted, and shouldParse() then returns false for an application/json request, so the parser quietly skips it.

defaultCharset across the parsers, for a request without a charset:

'UTF-8' 42 or {}
json() 415 unsupported charset "UTF-8" each request throws TypeError: charset.slice is not a function (500 in Express)
urlencoded() throws at construction throws at construction
text() 200 throws TypeError: encoding.toUpperCase is not a function inside the raw-body callback; Express cannot catch it and the process exits

All three treat 0, false and '' as 'utf-8'.

So one option gets three policies: checked at construction in urlencoded(), per request in json(), and not at all in text(), where a non-string value ends the process on the first request.

The question for the next major is which policy all options follow: check types at construction and throw, as limit and verify partly do, or coerce. Either way, defaultCharset needs lower-casing before the utf-8/iso-8859-1 checks, which is what #764 does.

Ngôn ngữ chính
JavaScript
Star
5.5k
Fork
802
Merge trung bình
7 giờ 54 phút
Pull request đã merge (30 ngày)
8

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của expressjs/body-parser

Tất cả issue của expressjs/body-parser

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.