Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use double quotes to preserve adjacent spaces correctly #95

Merged
merged 1 commit into from Oct 27, 2021

Commits on Oct 26, 2021

  1. Use double quotes to preserve adjacent spaces correctly

    I used this action as part of a workflow to add code formatted blocks.
    Using the guide in the readme I, adjacent spaces where not correctly
    preserved, i.e. the following
    ```
          - name: yolo
            id: get-comment-body
            run: |
              echo "\`\`\`" > tmp/comment.md
              echo "+--------------+" >> tmp/comment.md
              echo "|This is a test|" >> tmp/comment.md
              echo "+--------------+" >> tmp/comment.md
              echo "|     yolo     |" >> tmp/comment.md
              echo "+--------------+" >> tmp/comment.md
              echo "\`\`\`" >> tmp/comment.md
    
              cat tmp/comment.md
    
              # https://github.com/peter-evans/create-or-update-comment#setting-the-comment-body-from-a-file
              body="$(cat tmp/comment.md)"
              body="${body//'%'/'%25'}"
              body="${body//$'\n'/'%0A'}"
              body="${body//$'\r'/'%0D'}"
              echo ::set-output name=body::$body
    
          - name: Create or update comment
            uses: peter-evans/create-or-update-comment@v1
            with:
              body: ${{ steps.get-comment-body.outputs.body }}
              issue-number: ${{ github.event.pull_request.number }}
    ```
    produced this
    ```
    +--------------+
    |This is a test|
    +--------------+
    | yolo |
    +--------------+
    ```
    Adding the double quotes around `set-output` fixed this:
    ```
    +--------------+
    |This is a test|
    +--------------+
    |     yolo     |
    +--------------+
    ```
    Further I added double quotes also around the initial `cat`, because of
    this comment https://github.community/t/set-output-truncates-multiline-strings/16852/5
    > Here are a few observation. First, it is important to suppress word-splitting upon expansion in bash. This is easiest done by enclosing with double quotes:
    mfn committed Oct 26, 2021
    Copy the full SHA
    6484e4d View commit details
    Browse the repository at this point in the history