Actions
Bug #18956
closedKernel#sprintf - %c handles negative Integer argument in a confusing way
Bug #18956:
Kernel#sprintf - %c handles negative Integer argument in a confusing way
Description
Integer argument for %c means a character codepoint.
I've noticed two outcomes when argument is negative:
- exception
- broken/incorrect string
When exception is raised - its message a bit misleading and confusing:
sprintf("%c", -1000)
# => invalid character (ArgumentError)
sprintf("%c".encode('ascii'), -1)
# => 4294967295 out of char range (RangeError)
invalid character means there is a character, but actual argument is a codepoint. 4294967295 out of char range is about codepoint, but it mentions 4294967295 instead of actual argument -1.
In this case no exception is risen but the string is not valid:
Actions