From e953e6d054557eb69330f8a4e8d3a2cc7097328b Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 14 Sep 2021 13:38:39 -0400 Subject: [PATCH] Escape valid branch names Closes: #88 --- action.yml | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/action.yml b/action.yml index d610aa7..8a007e8 100644 --- a/action.yml +++ b/action.yml @@ -36,13 +36,20 @@ runs: - id: branch run: | if [[ "${{ github.ref }}" != "refs/tags/"* ]]; then - BASE_REF=${{ github.base_ref }} - HEAD_REF=${{ github.head_ref }} - REF=${{ github.ref }} - echo "::set-output name=base_ref_branch::${BASE_REF/refs\/heads\//}" - echo "::set-output name=head_ref_branch::${HEAD_REF/refs\/heads\//}" + BASE_REF=$(printf "%q" "${{ github.base_ref }}") + HEAD_REF=$(printf "%q" "${{ github.head_ref }}") + REF=$(printf "%q" "${{ github.ref }}") + + BASE_REF=${BASE_REF/refs\/heads\//} + HEAD_REF=${HEAD_REF/refs\/heads\//} + + echo "::set-output name=base_ref_branch::$(eval printf "%s" "$BASE_REF")" + echo "::set-output name=head_ref_branch::$(eval printf "%s" "$HEAD_REF")" + REF_BRANCH=${REF/refs\/pull\//} - echo "::set-output name=ref_branch::${REF_BRANCH/refs\/heads\//}" + REF_BRANCH=${REF_BRANCH/refs\/heads\//} + + echo "::set-output name=ref_branch::$(eval printf "%s" "$REF_BRANCH")" fi shell: bash - id: current_branch @@ -54,9 +61,10 @@ runs: echo "::set-output name=current_branch::${{ steps.branch.outputs.ref_branch }}" fi else - REF=${{ github.ref }} + REF=$(printf "%q" "${{ github.ref }}") REF_BRANCH=${REF/refs\/tags\/${{ inputs.strip_tag_prefix }}/} - echo "::set-output name=current_branch::$REF_BRANCH" + + echo "::set-output name=current_branch::$(eval printf "%s" "$REF_BRANCH")" fi shell: bash - id: default @@ -72,9 +80,10 @@ runs: - id: tag run: | if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then - REF=${{ github.ref }} + REF=$(printf "%q" "${{ github.ref }}") TAG=${REF/refs\/tags\/${{ inputs.strip_tag_prefix }}/} - echo "::set-output name=tag::$TAG" + + echo "::set-output name=tag::$(eval printf "%s" "$TAG")" echo "::set-output name=is_tag::true" else echo "::set-output name=is_tag::false"