Skip to content

Commit 56c90d6

Browse files
jsf9kmcdonnnj
authored andcommitted
Fix overly match-happy sed commands
We saw in cisagov/postfix-docker#47 that the sed commands in the bump_version.sh script could inadvertently match the CC0 version in the README.md file. This change escapes the periods in the version before passing it on to sed so that they only match periods and not just any character.
1 parent 94f78f9 commit 56c90d6

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

bump_version.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ VERSION_FILE=src/example/_version.py
1111
HELP_INFORMATION="bump_version.sh (show|major|minor|patch|prerelease|build|finalize)"
1212

1313
old_version=$(sed -n "s/^__version__ = \"\(.*\)\"$/\1/p" $VERSION_FILE)
14+
# Comment out periods so they are interpreted as periods and don't
15+
# just match any character
16+
old_version_regex=${old_version//\./\\\.}
1417

1518
if [ $# -ne 1 ]; then
1619
echo "$HELP_INFORMATION"
@@ -22,7 +25,7 @@ else
2225
# A temp file is used to provide compatability with macOS development
2326
# as a result of macOS using the BSD version of sed
2427
tmp_file=/tmp/version.$$
25-
sed "s/$old_version/$new_version/" $VERSION_FILE > $tmp_file
28+
sed "s/$old_version_regex/$new_version/" $VERSION_FILE > $tmp_file
2629
mv $tmp_file $VERSION_FILE
2730
git add $VERSION_FILE
2831
git commit -m"Bump version from $old_version to $new_version"
@@ -34,10 +37,10 @@ else
3437
# A temp file is used to provide compatability with macOS development
3538
# as a result of macOS using the BSD version of sed
3639
tmp_file=/tmp/version.$$
37-
sed "s/$old_version/$new_version/" $VERSION_FILE > $tmp_file
40+
sed "s/$old_version_regex/$new_version/" $VERSION_FILE > $tmp_file
3841
mv $tmp_file $VERSION_FILE
3942
git add $VERSION_FILE
40-
git commit -m"Bump version from $old_version to $new_version"
43+
git commit -m"Finalize version from $old_version to $new_version"
4144
git push
4245
;;
4346
show)

0 commit comments

Comments
 (0)