Skip to content

Skip sequence comments when resolving numeric tree paths - #2344

Open
spicysharkco wants to merge 1 commit into
getsops:mainfrom
spicysharkco:fix/sequence-comment-indices
Open

spicysharkco wants to merge 1 commit into
getsops:mainfrom
spicysharkco:fix/sequence-comment-indices

Conversation

@spicysharkco

Copy link
Copy Markdown

Encrypt this YAML with an age recipient:

items:
  # primary
  - first
  - second
sops encrypt --age <recipient> input.yaml > input.enc.yaml

sops decrypt --extract '["items"][1]' input.enc.yaml prints first; the expected output is second. With the same index [1], sops set input.enc.yaml '["items"][1]' '"replacement"' replaces first, and sops unset input.enc.yaml '["items"][1]' removes first.

Numeric extraction indexes the internal slice, which also holds the list's comments. Set and unset use the same raw indices.

This change maps numeric path indices to positions that skip comments in all three operations, including nested paths. Comments stay where they are. Before, [0] on this list printed the comment itself (value: ' primary', inline: false) and [2] printed second. Now [2] is out of bounds for extract and unset, and set appends.

The new test fails without the change.

Numeric paths in YAML lists counted stored comments as list items.
Extracting the second item could return the first, and set or unset
could change the wrong item.

Skip comments when mapping numeric path indices in extraction, set and
unset. Add a regression test covering comment positions, nested paths
and list bounds.

Signed-off-by: spicysharkco <321699413+spicysharkco@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant