fix: fix a bug when parsing attributes if no parseHTML method is provided, fix #2058

This commit is contained in:
Philipp Kühn 2021-11-08 21:27:46 +01:00
parent c94d2b0517
commit 5da313a548
2 changed files with 7 additions and 1 deletions

View File

@ -3,7 +3,7 @@ export default function fromString(value: any): any {
return value
}
if (value.match(/^\d*(\.\d+)?$/)) {
if (value.match(/^[+-]?(?:\d*\.)?\d+$/)) {
return Number(value)
}

View File

@ -9,6 +9,12 @@ describe('fromString', () => {
expect(value).to.eq('test')
})
it('should return an empty string', () => {
const value = fromString('')
expect(value).to.eq('')
})
it('should convert to a number', () => {
const value = fromString('1')