Reject a retention duration with characters outside its number-and-unit parts #237

Merged
clawbot merged 1 commits from issue-215-reject-unparsed-duration into next 2026-10-06 06:12:08 +02:00
Collaborator

Fixes #215.

parseDuration tried time.ParseDuration first and, when that failed, searched the input for number-and-unit pieces and skipped whatever lay between them. 1.0y became 0y, so snapshot create --prune --keep-newer-than 1.0y selected every snapshot of the backed-up names, the new one included; 2.1w became one week and 1,5y five years. The fallback now requires the whole input to be whole numbers each followed directly by a unit before it adds anything up. Anything else returns the existing invalid-duration error, so nothing is deleted.

A bare number is rejected before time.ParseDuration sees it: Go reads 0 and +0 as zero with no unit, and --keep-newer-than 0 selected every snapshot the same way.

Go-unit input takes the same path as before: 1.5h still parses, and a new table case pins that. Combined calendar units such as 2w3d and 1y6mo still work.

The table test adds 0, +0, 1.0y, 2.1w, 1,5y, 30 days, 30 days ago and x7d as errors and keeps every earlier case.

Judgement call: 30 days (a space between number and unit) used to be accepted and is now an error. The issue lists separators as rejected, and Go's units never allowed a space (30 s was already an error), so both halves of the grammar now agree. The README and help text show only unspaced examples.

Model: opus-5-5

Fixes https://git.eeqj.de/sneak/vaultik/issues/215. `parseDuration` tried `time.ParseDuration` first and, when that failed, searched the input for number-and-unit pieces and skipped whatever lay between them. `1.0y` became `0y`, so `snapshot create --prune --keep-newer-than 1.0y` selected every snapshot of the backed-up names, the new one included; `2.1w` became one week and `1,5y` five years. The fallback now requires the whole input to be whole numbers each followed directly by a unit before it adds anything up. Anything else returns the existing invalid-duration error, so nothing is deleted. A bare number is rejected before `time.ParseDuration` sees it: Go reads `0` and `+0` as zero with no unit, and `--keep-newer-than 0` selected every snapshot the same way. Go-unit input takes the same path as before: `1.5h` still parses, and a new table case pins that. Combined calendar units such as `2w3d` and `1y6mo` still work. The table test adds `0`, `+0`, `1.0y`, `2.1w`, `1,5y`, `30 days`, `30 days ago` and `x7d` as errors and keeps every earlier case. Judgement call: `30 days` (a space between number and unit) used to be accepted and is now an error. The issue lists separators as rejected, and Go's units never allowed a space (`30 s` was already an error), so both halves of the grammar now agree. The README and help text show only unspaced examples. Model: opus-5-5
clawbot added the needs-review label 2026-10-06 05:00:26 +02:00
clawbot self-assigned this 2026-10-06 05:00:27 +02:00
Author
Collaborator
  1. internal/vaultik/helpers.go:152: a bare 0 (and +0) is still accepted, because time.ParseDuration reads it as zero before the new whole-input check runs. snapshot create --prune --keep-newer-than 0 still selects every snapshot of the backed-up names, the new one included, and snapshot purge --older-than 0 --force deletes them all. The definition of done in #215 rejects any input that is not entirely number-and-unit parts, and 0 has no unit. The doc comment at helpers.go:142 ("A bare number ... rejected") and the new TODO.md:25 entry are false while it parses. Acceptable: a bare number of any value, signed or not, is an error, and TestParseDuration has 0 and +0 error cases beside 6 (helpers_test.go:76).

Model: opus-5-5

1. `internal/vaultik/helpers.go:152`: a bare `0` (and `+0`) is still accepted, because `time.ParseDuration` reads it as zero before the new whole-input check runs. `snapshot create --prune --keep-newer-than 0` still selects every snapshot of the backed-up names, the new one included, and `snapshot purge --older-than 0 --force` deletes them all. The definition of done in https://git.eeqj.de/sneak/vaultik/issues/215 rejects any input that is not entirely number-and-unit parts, and `0` has no unit. The doc comment at `helpers.go:142` ("A bare number ... rejected") and the new `TODO.md:25` entry are false while it parses. Acceptable: a bare number of any value, signed or not, is an error, and `TestParseDuration` has `0` and `+0` error cases beside `6` (`helpers_test.go:76`). Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-06 05:28:49 +02:00
clawbot added 1 commit 2026-10-06 05:41:25 +02:00
parseDuration fell back to an unanchored search for number-and-unit
pieces when time.ParseDuration failed, and skipped everything in
between. 1.0y became 0, so `snapshot create --prune --keep-newer-than
1.0y` deleted every snapshot of the backed-up names, the new one
included. 2.1w became one week and 1,5y five years. The fallback now
requires the whole input to be whole-number-and-unit parts with nothing
between them. A bare number is rejected before time.ParseDuration sees
it, since Go reads 0 and +0 as zero with no unit.

Judgement call: a space between number and unit (`30 days`) was
accepted and is now an error, matching Go's own units.

Model: opus-5-5
clawbot force-pushed issue-215-reject-unparsed-duration from 0f2ebbdafa to 969b3c1703 2026-10-06 05:41:25 +02:00 Compare
Author
Collaborator

Rework delta:

  1. A bare number is now rejected before time.ParseDuration sees it, so 0 and +0 return the invalid-duration error like 6. TestParseDuration has 0 and +0 error cases beside 6; the TODO.md entry lists a bare 0 among the rejected inputs. The doc comment needed no change, since it is now true.

Model: opus-5-5

Rework delta: 1. A bare number is now rejected before `time.ParseDuration` sees it, so `0` and `+0` return the invalid-duration error like `6`. `TestParseDuration` has `0` and `+0` error cases beside `6`; the `TODO.md` entry lists a bare `0` among the rejected inputs. The doc comment needed no change, since it is now true. Model: opus-5-5
clawbot added needs-review and removed needs-rework labels 2026-10-06 05:41:36 +02:00
Author
Collaborator

Review passed.
Model: opus-5-5

Review passed. Model: opus-5-5
clawbot merged commit 713be502bd into next 2026-10-06 06:12:08 +02:00
clawbot deleted branch issue-215-reject-unparsed-duration 2026-10-06 06:12:08 +02:00
Sign in to join this conversation.