detached c082b4b

fix(command): reject non-canonical decimals

commit
c082b4bc6f34459a07f784e980fc4ca8cfa04c49
author
brice · · 2026-07-11 13:00 UTC
parent
0ac83ce
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
2 files · +7 -1
M internal/usecase/command/command.go +1 -1
@@ -11,7 +11,7 @@ var ErrInvalidArguments = errors.New("invalid command arguments")
1111 // ParsePositiveDecimal accepts exactly one base-10 positive decimal value.
1212 // It deliberately rejects signs, whitespace, zero, and non-canonical forms.
1313 func ParsePositiveDecimal(args []string) (int, error) {
14- if len(args) != 1 || args[0] == "" {
14+ if len(args) != 1 || args[0] == "" || (len(args[0]) > 1 && args[0][0] == '0') {
1515 return 0, ErrInvalidArguments
1616 }
1717 for _, r := range args[0] {
@@ -11,7 +11,7 @@ var ErrInvalidArguments = errors.New("invalid command arguments")
11 // ParsePositiveDecimal accepts exactly one base-10 positive decimal value.11 // ParsePositiveDecimal accepts exactly one base-10 positive decimal value.
12 // It deliberately rejects signs, whitespace, zero, and non-canonical forms.12 // It deliberately rejects signs, whitespace, zero, and non-canonical forms.
13 func ParsePositiveDecimal(args []string) (int, error) {13 func ParsePositiveDecimal(args []string) (int, error) {
14- if len(args) != 1 || args[0] == "" {14+ if len(args) != 1 || args[0] == "" || (len(args[0]) > 1 && args[0][0] == '0') {
15 return 0, ErrInvalidArguments15 return 0, ErrInvalidArguments
16 }16 }
17 for _, r := range args[0] {17 for _, r := range args[0] {
M internal/usecase/command/command_test.go +6 -0
@@ -13,6 +13,12 @@ func TestParsePositiveDecimal(t *testing.T) {
1313 invalid bool
1414 }{
1515 {"one", []string{"1"}, 1, false},
16+ {"multi-digit", []string{"42"}, 42, false},
17+ {"overflow", []string{"999999999999999999999999999999999999"}, 0, true},
18+ {"leading zero", []string{"01"}, 0, true},
19+ {"multiple leading zeros", []string{"0001"}, 0, true},
20+ {"all zeros", []string{"00"}, 0, true},
21+ {"leading zero on multi-digit value", []string{"010"}, 0, true},
1622 {"zero", []string{"0"}, 0, true},
1723 {"negative", []string{"-1"}, 0, true},
1824 {"extra", []string{"1", "2"}, 0, true},
@@ -13,6 +13,12 @@ func TestParsePositiveDecimal(t *testing.T) {
13 invalid bool13 invalid bool
14 }{14 }{
15 {"one", []string{"1"}, 1, false},15 {"one", []string{"1"}, 1, false},
16+ {"multi-digit", []string{"42"}, 42, false},
17+ {"overflow", []string{"999999999999999999999999999999999999"}, 0, true},
18+ {"leading zero", []string{"01"}, 0, true},
19+ {"multiple leading zeros", []string{"0001"}, 0, true},
20+ {"all zeros", []string{"00"}, 0, true},
21+ {"leading zero on multi-digit value", []string{"010"}, 0, true},
16 {"zero", []string{"0"}, 0, true},22 {"zero", []string{"0"}, 0, true},
17 {"negative", []string{"-1"}, 0, true},23 {"negative", []string{"-1"}, 0, true},
18 {"extra", []string{"1", "2"}, 0, true},24 {"extra", []string{"1", "2"}, 0, true},

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 12

Tags 11

↑↓ moveenter openesc close