Skip to content

Conversation

@sagikazarmark
Copy link
Collaborator

Fixes #204
Fixes #189
Fixes #172
Fixes #210
Fixes #170

Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
@sagikazarmark sagikazarmark changed the title Support converting float string numbers to integer types May 31, 2025
@sagikazarmark sagikazarmark merged commit b4445f6 into master May 31, 2025
18 checks passed
@sagikazarmark sagikazarmark deleted the float-string branch May 31, 2025 15:23

func parseUint[T unsigned](s string) (T, error) {
v, err := strconv.ParseUint(trimZeroDecimal(s), 0, 0)
v, err := strconv.ParseUint(trimDecimal(s), 0, 0)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm suspicious here

It works for the expected case. The one that caused to code this.

But what about the string "10...17" previously it was returning an error, now it will happily return 10

https://go.dev/play/p/bkiLc4jdBEH

vs

https://go.dev/play/p/VyqcbrcMEWk

The issue is worst if you consider:

  • 10.foobar (invalid)
  • 10.0i (a complex)
  • 10.0E9 (unsupported syntax previously)

All of them are now returning 10

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. Let me try to fix that.

cloudxxx8 added a commit to cloudxxx8/device-rest-go that referenced this pull request Jun 9, 2025
Fixed the unit tests to meet the change of spf13 v1.9
spf13/cast#261

Signed-off-by: Cloud Tsai <cloudxxx8@gmail.com>
judehung pushed a commit to edgexfoundry/device-rest-go that referenced this pull request Jun 9, 2025
Fixed the unit tests to meet the change of spf13 v1.9
spf13/cast#261

Signed-off-by: Cloud Tsai <cloudxxx8@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants