Skip to content

fish converts an empty string to zero in numeric contexts #3346

Closed
@krader1961

Description

@krader1961

Several recent issues involving the test and printf builtins brought to light that fish is inconsistent about how it treats an empty, null, string when converting it to a number. For example, test "" -ge 0 is considered true because the empty string is converted to a zero. Doing printf '%f\n' "" prints 0.000000. Yet the similar printf '%d\n' "" on macOS Sierra (as of git commit eeb42f5) reports the error ": Invalid argument". Whereas printf '%f\n' "" prints "0.00000". On the other hand the printf '%d\n' "" on Ubuntu 16.04 (with the same version of fish) prints "0".

While I am curious why Ubuntu and macOS Sierra handle the printf '%d\n' "" case differently it's orthogonal to the core point of this issue. Which is, fish should consistently treat an empty, null, string (i.e., "") as an invalid number. The current behavior is problematic. It will also be inconsistent if the change I believe @floam is working on to make the test "" -ge 0 scenario be an error rather than return a true (zero) status is merged.

See also issue #3334.

Metadata

Metadata

Assignees

Labels

bugSomething that's not working as intendedrelease notesSomething that is or should be mentioned in the release notes

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions