cmd/age: accept leading whitespace before armored data

It was already accepted by the API, but the CLI did not handle it while
peeking to detect armored input.
This commit is contained in:
Filippo Valsorda
2025-12-23 22:23:41 +01:00
parent 6aae5b48ea
commit b4cdeef465
3 changed files with 28 additions and 2 deletions
+4 -1
View File
@@ -5,6 +5,7 @@ import (
"bytes"
"fmt"
"io"
"strings"
"filippo.io/age/armor"
"filippo.io/age/internal/format"
@@ -38,7 +39,9 @@ func Inspect(r io.Reader, fileSize int64) (*Metadata, error) {
tr := &trackReader{r: r}
br := bufio.NewReader(tr)
if start, _ := br.Peek(len(armor.Header)); string(start) == armor.Header {
const maxWhitespace = 1024
start, _ := br.Peek(maxWhitespace + len(armor.Header))
if strings.HasPrefix(string(bytes.TrimSpace(start)), armor.Header) {
r = armor.NewReader(br)
data.Armor = true
} else {