@@ -215,7 +215,9 @@ func ParseBestEffort(s string) float64 {
215
215
216
216
// the integer part might be elided to remain compliant
217
217
// with https://go.dev/ref/spec#Floating-point_literals
218
- intPartElided := s [i ] == '.'
218
+ if s [i ] == '.' && (i + 1 >= uint (len (s )) || s [i + 1 ] < '0' || s [i + 1 ] > '9' ) {
219
+ return 0
220
+ }
219
221
220
222
d := uint64 (0 )
221
223
j := i
@@ -236,7 +238,7 @@ func ParseBestEffort(s string) float64 {
236
238
}
237
239
break
238
240
}
239
- if i <= j && ! intPartElided {
241
+ if i <= j && s [ i ] != '.' {
240
242
s = s [i :]
241
243
if strings .HasPrefix (s , "+" ) {
242
244
s = s [1 :]
@@ -267,9 +269,6 @@ func ParseBestEffort(s string) float64 {
267
269
// Parse fractional part.
268
270
i ++
269
271
if i >= uint (len (s )) {
270
- if intPartElided {
271
- return 0
272
- }
273
272
// the fractional part may be elided to remain compliant
274
273
// with https://go.dev/ref/spec#Floating-point_literals
275
274
return f
@@ -305,9 +304,6 @@ func ParseBestEffort(s string) float64 {
305
304
}
306
305
}
307
306
if s [i ] == 'e' || s [i ] == 'E' {
308
- if intPartElided {
309
- return 0
310
- }
311
307
// Parse exponent part.
312
308
i ++
313
309
if i >= uint (len (s )) {
@@ -377,7 +373,9 @@ func Parse(s string) (float64, error) {
377
373
378
374
// the integer part might be elided to remain compliant
379
375
// with https://go.dev/ref/spec#Floating-point_literals
380
- intPartElided := s [i ] == '.'
376
+ if s [i ] == '.' && (i + 1 >= uint (len (s )) || s [i + 1 ] < '0' || s [i + 1 ] > '9' ) {
377
+ return 0 , fmt .Errorf ("missing integer and fractional part in %q" , s )
378
+ }
381
379
382
380
d := uint64 (0 )
383
381
j := i
@@ -398,7 +396,7 @@ func Parse(s string) (float64, error) {
398
396
}
399
397
break
400
398
}
401
- if i <= j && ! intPartElided {
399
+ if i <= j && s [ i ] != '.' {
402
400
ss := s [i :]
403
401
if strings .HasPrefix (ss , "+" ) {
404
402
ss = ss [1 :]
@@ -429,9 +427,6 @@ func Parse(s string) (float64, error) {
429
427
// Parse fractional part.
430
428
i ++
431
429
if i >= uint (len (s )) {
432
- if intPartElided {
433
- return 0 , fmt .Errorf ("cannot parse integer or fractional part in %q" , s )
434
- }
435
430
// the fractional part might be elided to remain compliant
436
431
// with https://go.dev/ref/spec#Floating-point_literals
437
432
return f , nil
@@ -467,9 +462,6 @@ func Parse(s string) (float64, error) {
467
462
}
468
463
}
469
464
if s [i ] == 'e' || s [i ] == 'E' {
470
- if intPartElided {
471
- return 0 , fmt .Errorf ("cannot parse integer part in %q" , s )
472
- }
473
465
// Parse exponent part.
474
466
i ++
475
467
if i >= uint (len (s )) {
0 commit comments