capricorn86 / happy-dom

A JavaScript implementation of a web browser without its graphical user interface
MIT License
3.09k stars 185 forks source link

FormData constructed from a <form> element contains duplicate values #1426

Open cmd-johnson opened 2 months ago

cmd-johnson commented 2 months ago

Describe the bug When constructing a FormData instance from an HTMLFormElement containing an input that has both an id and a name, the input's value appears twice in the form data.

To Reproduce

describe('FormData', () => {
  describe('Constructor', () => {
    it('Contains the value of named inputs with ids only once', () => {
      const form = document.createElement('form');
      const input = document.createElement('input');

      input.name = 'inputName';
      input.id = 'inputId';
      input.value = 'testing';

      form.appendChild(input);

      const formData = new window.FormData(form);

      expect(formData.getAll('inputName')).toEqual(['testing']);
    });
  });
});

Expected behavior The resulting formData should only have a single value for the inputName key. Calling formData.getAll('inputName') returns ['testing'].

Current behavior Calling formData.getAll('inputName') returns ['testing', 'testing'].

Device: