diff --git a/.github/scripts/test_strip_shell_comments.sh b/.github/scripts/test_strip_shell_comments.sh index ca6b1bd020..8341d3b1d2 100755 --- a/.github/scripts/test_strip_shell_comments.sh +++ b/.github/scripts/test_strip_shell_comments.sh @@ -72,6 +72,14 @@ else ok "plain and indented comment lines are dropped" fi +# #2386: blank lines stay, so the shipped script keeps its paragraph breaks. +printf '#!/bin/sh\necho one\n\necho two\n' > "$WORK/blank.sh" +if [ "$(strip "$WORK/blank.sh" | wc -l)" = 4 ]; then + ok "blank lines survive" +else + bad "a blank line was dropped" +fi + live=$(grep -c LIVE "$WORK/fixture.out") if [ "$live" = 6 ]; then ok "heredoc bodies, multi-line strings and continuations are left alone (6/6)" diff --git a/general/scripts/strip-shell-comments.awk b/general/scripts/strip-shell-comments.awk index 0f6c757548..f544bfaa45 100644 --- a/general/scripts/strip-shell-comments.awk +++ b/general/scripts/strip-shell-comments.awk @@ -1,4 +1,5 @@ -# Drop whole-line comments and blank lines from a POSIX shell script. +# Drop whole-line comments from a POSIX shell script. +# Keep blank lines to preserve readability. See #2386. # # Comments are worth writing and worth keeping in the tree, but every byte of # them is also flashed to an 8MB camera. sysupgrade alone reached 52KB, 57% of @@ -104,7 +105,7 @@ BEGIN { nd = 0; sq = 0; dq = 0; cont = 0; prev_cont = 0 } next } - if (/^[ \t]*$/) next + if (/^[ \t]*$/) { print; next } code = code_of($0) if (code ~ /^[ \t]*$/) next # the line was only a comment