sindresorhus / got

🌐 Human-friendly and powerful HTTP request library for Node.js
MIT License
14.27k stars 935 forks source link

node v18's FormData "-\n-" will become "-\r\n-" #2203

Closed qidizi closed 1 year ago

qidizi commented 1 year ago

Describe the bug

Actual behavior

request:

// node global.FormData,not npm
form = new FormData();
    form.set('imN_notRN','a\na');

// print :    imN_notRN value "a\na"  
    console.log('imN_notRN value',JSON.stringify(form.get('imN_notRN')))

  // php "echo json_encode($_POST);"  will print :    { imN_notRN: 'a\r\na' } 
   console.log (await got({
        url: 'http://127.0.0.1:8000/?',
        method: 'POST',
        body: form,
        responseType: 'json'
    }).json());

Expected behavior

php "echo json_encode($_POST);" will print : { imN_notRN: 'a\na' }

Code to reproduce

...

Checklist

szmarczak commented 1 year ago

https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data