Skip to content

Conversation

@mateonunez
Copy link
Contributor

This PR would implement #1872.

Context

Actually, the FormData class needs the following declaration to work:

  class FormData {
    constructor () {}

    append () {}
    delete () {}
    get () {}
    getAll () {}
    has () {}
    set () {}
    entries () {}
    keys () {}
    values () {}
    forEach () {}
  }

The isFormDataLike method was improved by checking the constructor.name and the declaration of those methods. This makes that control more strict and flexible. The check would be linear, there is no way to guess what API is requested by the chunk. This check allows third-party libraries to be compatible with this control.

Tests

The tests were updated by adding some cases where the check should return false or true.

@codecov-commenter
Copy link

codecov-commenter commented Jan 21, 2023

Codecov Report

Base: 90.35% // Head: 90.33% // Decreases project coverage by -0.02% ⚠️

Coverage data is based on head (9dd6353) compared to base (1813408).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1875      +/-   ##
==========================================
- Coverage   90.35%   90.33%   -0.02%     
==========================================
  Files          70       70              
  Lines        6044     6044              
==========================================
- Hits         5461     5460       -1     
- Misses        583      584       +1     
Impacted Files Coverage Δ
lib/core/util.js 97.93% <100.00%> (ø)
lib/core/request.js 98.85% <0.00%> (-0.58%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ronag
Copy link
Member

ronag commented Jan 21, 2023

Can you add a test for the npm package form-data. An instance of that should not be formdata like

@mateonunez
Copy link
Contributor Author

Can you add a test for the npm package form-data. An instance of that should not be formdata like

Sure! I've installed the package onto devDependencies and included it in the tests.

@ronag ronag merged commit d7602f6 into nodejs:main Jan 21, 2023
@mateonunez mateonunez deleted the perf/form-data-check branch January 21, 2023 13:33
anonrig pushed a commit to anonrig/undici that referenced this pull request Apr 4, 2023
metcoder95 pushed a commit to metcoder95/undici that referenced this pull request Jul 21, 2023
crysmags pushed a commit to crysmags/undici that referenced this pull request Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants