The idea for strconv originates in c (see atoi etc), and c also has 0-octal notation.
Go is simply mimicing c in this regard.
> What was the Golang team thinking?!
They were helping you not misuse the function, as you are doing in your example (you are trying to parse strings containing invalid number representations as integers).
Thanks for your comment. It kind of makes a little sense now. I just wished the octals needed a stricter prefix like "0o" as they are not very common compared to decimal and hex (in my experience at least). The way Python casts strings with leading zeros makes more sense to me. Later I'll update the post with your feedback. Thanks.
> If base == 0, the base is implied by the string’s prefix: base 16 for "0x", base 8 for "0", and base 10 otherwise. For bases 1, below 0 or above 36 an error is returned.
A better solution is to always provide the base (e.g. 10) rather than using 0 if you don't want special interpretation of '0x' and '0' prefixes. That should be in Hugo. The problem is not with the golang library which was well documented and always worked as such. By placing any blame on the golang library, there's less incentive to fix Hugo.
That's a valid point. I have made that suggestion to the Hugo devs[1]. Someone on Reddit also suggested using strconv.Atoi() instead of ParseInt(). I have added to the suggestion too.
5 comments
[ 3.3 ms ] story [ 18.8 ms ] threadThe idea for strconv originates in c (see atoi etc), and c also has 0-octal notation.
Go is simply mimicing c in this regard.
> What was the Golang team thinking?!
They were helping you not misuse the function, as you are doing in your example (you are trying to parse strings containing invalid number representations as integers).
A better solution is to always provide the base (e.g. 10) rather than using 0 if you don't want special interpretation of '0x' and '0' prefixes. That should be in Hugo. The problem is not with the golang library which was well documented and always worked as such. By placing any blame on the golang library, there's less incentive to fix Hugo.
[1]: https://github.com/gohugoio/hugo/issues/4628#issuecomment-38...