Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 12ecce5

Browse files
defccyyx990803
authored andcommitted
[1.x]Empty string should not be casted to 0 (fix vuejs#3577, vuejs#3541) (vuejs#4118)
* empty string should not be casted to 0. Backport it from vue2 * trim whitespace * fix coding style * fix coding style
1 parent 3fc8331 commit 12ecce5

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

‎src/util/lang.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,13 @@ export function _toString (value) {
126126
*/
127127

128128
export function toNumber (value) {
129-
if (typeof value !== 'string') {
129+
if (typeof value !== 'string' || value.trim() === '') {
130130
return value
131-
} else {
132-
var parsed = Number(value)
133-
return isNaN(parsed)
134-
? value
135-
: parsed
136131
}
132+
var parsed = Number(value)
133+
return isNaN(parsed)
134+
? value
135+
: parsed
137136
}
138137

139138
/**

0 commit comments

Comments
 (0)