Describe the bug
formToJSON is a helpful function and I use it when I have a form to submit, but do additional validation on individual properties before sending it to backend. However, when I have a form input with a name like user-name, this property is converted to object as { user: { name: '' } } instead of { 'user-name': '' }. I think this is an unexpected behavior.
To Reproduce
var axios = require("axios")
var { JSDOM } = require("jsdom")
var { FormData } = new JSDOM().window;
const formData = new FormData();
formData.append('user-name', 'johndoe');
const result = axios.formToJSON(formData);
console.log(result);
Code snippet
Try the above snippet.
Expected behavior
Properties should only be splitted with . and [ ]. Currently, they are splitted by - and (space) too.
While it can be argued that . and [ ] can also be inside a property key, they are less likely than - and . As an advanced option, there can be an escape character to allow this case. However this may be an overkill.
Axios Version
1.2.1
Adapter Version
Browser
All browsers
Browser Version
All versions
Node.js Version
All versions
OS
All OS
Additional Library Versions
Additional context/Screenshots
Describe the bug
formToJSONis a helpful function and I use it when I have a form to submit, but do additional validation on individual properties before sending it to backend. However, when I have a form input with a name likeuser-name, this property is converted to object as{ user: { name: '' } }instead of{ 'user-name': '' }. I think this is an unexpected behavior.To Reproduce
Code snippet
Try the above snippet.
Expected behavior
Properties should only be splitted with
.and[ ]. Currently, they are splitted by-and(space) too.While it can be argued that
.and[ ]can also be inside a property key, they are less likely than-and. As an advanced option, there can be an escape character to allow this case. However this may be an overkill.Axios Version
1.2.1
Adapter Version
Browser
All browsers
Browser Version
All versions
Node.js Version
All versions
OS
All OS
Additional Library Versions
Additional context/Screenshots