mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 04:18:17 +08:00
printf: Print special error for invalid octal numbers
(tbh these were always a mistake)
See #9035
(cherry picked from commit 13a9f6b64e
)
This commit is contained in:
parent
9397ede963
commit
89a30841f2
|
@ -4,6 +4,7 @@ fish 3.5.1 (released ???)
|
|||
This release of fish introduces the following small enhancements:
|
||||
|
||||
- Cursor shaping for Vi mode is enabled by default in tmux, and will be used if the outer terminal is capable (:issue:`8981`).
|
||||
- ``printf`` returns a better error when used with arguments interpreted as octal numbers (:issue:`9035`).
|
||||
|
||||
This release also fixes a number of problems identified in fish 3.5.0.
|
||||
|
||||
|
|
|
@ -263,6 +263,12 @@ void builtin_printf_state_t::verify_numeric(const wchar_t *s, const wchar_t *end
|
|||
} else {
|
||||
// This isn't entirely fatal - the value should still be printed.
|
||||
this->nonfatal_error(_(L"%ls: value not completely converted (can't convert '%ls')"), s, end);
|
||||
// Warn about octal numbers as they can be confusing.
|
||||
// Do it if the unconverted digit is a valid hex digit,
|
||||
// because it could also be an "0x" -> "0" typo.
|
||||
if (*s == L'0' && iswxdigit(*end)) {
|
||||
this->nonfatal_error(_(L"Hint: a leading '0' without an 'x' indicates an octal number"), s, end);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,3 +95,27 @@ printf '%d\n' 15.1
|
|||
# CHECKERR: 15.1: value not completely converted (can't convert '.1')
|
||||
echo $status
|
||||
# CHECK: 1
|
||||
|
||||
printf '%d\n' 07
|
||||
# CHECK: 7
|
||||
echo $status
|
||||
# CHECK: 0
|
||||
printf '%d\n' 08
|
||||
# CHECK: 0
|
||||
# CHECKERR: 08: value not completely converted (can't convert '8')
|
||||
# CHECKERR: Hint: a leading '0' without an 'x' indicates an octal number
|
||||
echo $status
|
||||
# CHECK: 1
|
||||
|
||||
printf '%d\n' 0f
|
||||
# CHECK: 0
|
||||
# CHECKERR: 0f: value not completely converted (can't convert 'f')
|
||||
# CHECKERR: Hint: a leading '0' without an 'x' indicates an octal number
|
||||
echo $status
|
||||
# CHECK: 1
|
||||
|
||||
printf '%d\n' 0g
|
||||
# CHECK: 0
|
||||
# CHECKERR: 0g: value not completely converted (can't convert 'g')
|
||||
echo $status
|
||||
# CHECK: 1
|
||||
|
|
Loading…
Reference in New Issue
Block a user