CodelyTV / pr-size-labeler

🏷 Visualize and optionally limit the size of your Pull Requests
https://github.com/marketplace/actions/pull-request-size-labeler
MIT License
336 stars 58 forks source link

πŸ› Add Escaped Double Quotes to `comment` #82

Closed keunhyung-chung closed 1 week ago

keunhyung-chung commented 2 weeks ago

What type of PR is this? (check all applicable)

Description

Even if the PR size is over l_max_size, this actions fails to comment to the PR with the following message:

image


This is because #50 changed the sanitiation logic of arguments:

image


For example, before #50

$ a="--message_if_xl=\"This PR exceeds the recommended size of 1000 lines (additions + deletions). Please make sure you are NOT addressing multiple issues with one PR and split the PR if necessary.\""
$ echo "$a" | tr -d '\n'| sed "s/'//g"| sed "s/’//g"
--message_if_xl="This PR exceeds the recommended size of 1000 lines (additions + deletions). Please make sure you are NOT addressing multiple issues with one PR and split the PR if necessary."

the argument contains ".

However, after #50

$ echo "$a" | tr '\n' ' ' | xargs echo | sed "s/'//g"| sed "s/’//g"
--message_if_xl=This PR exceeds the recommended size of 1000 lines (additions + deletions). Please make sure you are NOT addressing multiple issues with one PR and split the PR if necessary.

the argument loose ".

How to test

Without Quotes

$ curl -L \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer $GITHUB_TOKEN" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/repos/CodelyTV/pr-size-labeler/issues/82/comments \
  -d "{\"body\":hello}"
{
  "message": "Problems parsing JSON",
  "documentation_url": "https://docs.github.com/rest/issues/comments#create-an-issue-comment",
  "status": "400"
}

With Quotes

$ curl -L \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer $GITHUB_TOKEN" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/repos/CodelyTV/pr-size-labeler/issues/82/comments \
  -d "{\"body\":\"hello\"}"
{
  "url": "https://api.github.com/repos/CodelyTV/pr-size-labeler/issues/comments/2320573142",
  "html_url": "https://github.com/CodelyTV/pr-size-labeler/pull/82#issuecomment-2320573142",
  "issue_url": "https://api.github.com/repos/CodelyTV/pr-size-labeler/issues/82",
  "id": 2320573142,
  "node_id": "IC_kwDODoQbjM6KUSLW",
  "user": {
    "login": "keunhyung-chung",
    "id": 12574208,
    "node_id": "MDQ6VXNlcjEyNTc0MjA4",
    "avatar_url": "https://avatars.githubusercontent.com/u/12574208?u=3e6202a7d076a402f4de01c29f9f8aff06b3a84b&v=4",
    "gravatar_id": "",
    "url": "https://api.github.com/users/keunhyung-chung",
    "html_url": "https://github.com/keunhyung-chung",
    "followers_url": "https://api.github.com/users/keunhyung-chung/followers",
    "following_url": "https://api.github.com/users/keunhyung-chung/following{/other_user}",
    "gists_url": "https://api.github.com/users/keunhyung-chung/gists{/gist_id}",
    "starred_url": "https://api.github.com/users/keunhyung-chung/starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/keunhyung-chung/subscriptions",
    "organizations_url": "https://api.github.com/users/keunhyung-chung/orgs",
    "repos_url": "https://api.github.com/users/keunhyung-chung/repos",
    "events_url": "https://api.github.com/users/keunhyung-chung/events{/privacy}",
    "received_events_url": "https://api.github.com/users/keunhyung-chung/received_events",
    "type": "User",
    "site_admin": false
  },
  "created_at": "2024-08-30T09:05:07Z",
  "updated_at": "2024-08-30T09:05:07Z",
  "author_association": "NONE",
  "body": "hello",
  "reactions": {
    "url": "https://api.github.com/repos/CodelyTV/pr-size-labeler/issues/comments/2320573142/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
  },
  "performed_via_github_app": null
}
keunhyung-chung commented 2 weeks ago

hello