Skip to content

Commit

Permalink
Fix overly match-happy sed commands
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jsf9k authored and mcdonnnj committed Nov 21, 2022
1 parent 362fad5 commit 1a8ab89
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions bump_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ README_FILE=README.md
HELP_INFORMATION="bump_version.sh (show|major|minor|patch|prerelease|build|finalize)"

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

if [ $# -ne 1 ]; then
echo "$HELP_INFORMATION"
Expand All @@ -21,9 +24,9 @@ else
new_version=$(python -c "import semver; print(semver.bump_$1('$old_version'))")
echo Changing version from "$old_version" to "$new_version"
tmp_file=/tmp/version.$$
sed "s/$old_version/$new_version/" $VERSION_FILE > $tmp_file
sed "s/$old_version_regex/$new_version/" $VERSION_FILE > $tmp_file
mv $tmp_file $VERSION_FILE
sed "s/$old_version/$new_version/" $README_FILE > $tmp_file
sed "s/$old_version_regex/$new_version/" $README_FILE > $tmp_file
mv $tmp_file $README_FILE
git add $VERSION_FILE $README_FILE
git commit -m"Bump version from $old_version to $new_version"
Expand All @@ -33,12 +36,12 @@ else
new_version=$(python -c "import semver; print(semver.finalize_version('$old_version'))")
echo Changing version from "$old_version" to "$new_version"
tmp_file=/tmp/version.$$
sed "s/$old_version/$new_version/" $VERSION_FILE > $tmp_file
sed "s/$old_version_regex/$new_version/" $VERSION_FILE > $tmp_file
mv $tmp_file $VERSION_FILE
sed "s/$old_version/$new_version/" $README_FILE > $tmp_file
sed "s/$old_version_regex/$new_version/" $README_FILE > $tmp_file
mv $tmp_file $README_FILE
git add $VERSION_FILE $README_FILE
git commit -m"Bump version from $old_version to $new_version"
git commit -m"Finalize version from $old_version to $new_version"
git push
;;
show)
Expand Down

0 comments on commit 1a8ab89

Please sign in to comment.