From 01004bd27ba3dd17be454268fc635fb890d67c80 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Fri, 4 Aug 2023 08:43:53 +0200 Subject: [PATCH] [PR #7046/c7fa11d5 backport][stable-7] snap: Only treat `---` as an info separator when it's preceded by newline (#7063) snap: Only treat `---` as an info separator when it's preceded by newline (#7046) * Only treat `---` as an info separator when it's preceded by newline The code for splitting the output of `snap info` for multiple snaps can't assume that `---` separates snaps any time it appears in the output; it needs to treat that as the separator only when it's at the start of a line. Otherwise it breaks if any snap uses `---` in its description text, which, e.g., the `bw` snap does as of the date of this commit. Fixes #7045. * Add changelog fragment * Add a comment explaining why \n is necessary before --- * Update changelogs/fragments/7046-snap-newline-before-separator.yml Co-authored-by: Felix Fontein --------- Co-authored-by: Jonathan Kamens Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> Co-authored-by: Felix Fontein (cherry picked from commit c7fa11d576db681b074b626fd715925727f24004) Co-authored-by: Jonathan Kamens --- changelogs/fragments/7046-snap-newline-before-separator.yml | 2 ++ plugins/modules/snap.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/7046-snap-newline-before-separator.yml diff --git a/changelogs/fragments/7046-snap-newline-before-separator.yml b/changelogs/fragments/7046-snap-newline-before-separator.yml new file mode 100644 index 0000000000..a2b6ded381 --- /dev/null +++ b/changelogs/fragments/7046-snap-newline-before-separator.yml @@ -0,0 +1,2 @@ +bugfixes: + - snap - fix crash when multiple snaps are specified and one has ``---`` in its description (https://github.com/ansible-collections/community.general/pull/7046). diff --git a/plugins/modules/snap.py b/plugins/modules/snap.py index f92f42636e..485744d910 100644 --- a/plugins/modules/snap.py +++ b/plugins/modules/snap.py @@ -303,7 +303,10 @@ class Snap(StateModuleHelper): return [name] def process_many(rc, out, err): - outputs = out.split("---") + # This needs to be "\n---" instead of just "---" because otherwise + # if a snap uses "---" in its description then that will incorrectly + # be interpreted as a separator between snaps in the output. + outputs = out.split("\n---") res = [] for sout in outputs: res.extend(process_one(rc, sout, ""))