Skip to content

Unexpected token #5

Open
Open
@lhunath

Description

@lhunath

There appears to be something dodgy going on when PR Badge processes JavaScript or injects output into the badge. This was made evident when I attempted to do some more advanced JavaScript processing of the payload data:

- label: Howdy
  message: "$payload.pull_request.labels.filter(label => label.name.toLowerCase().includes('blocked')).map(label => label.name.replace(/blocked /i, '')).join(', ')"
  when: "$payload.pull_request.labels.filter(label => label.name.toLowerCase().includes('blocked'))"

The result is the following badge in my PR:

![SyntaxError: Unexpected token ')'](https://badgen.net/badge/Howdy/SyntaxError%3A%20Unexpected%20token%20')'/red) [<img width="16" alt="Powered by Pull Request Badge" src="https://user-images.githubusercontent.com/1393946/111216524-d2bb8e00-85d4-11eb-821b-ed4c00989c02.png">](https://pullrequestbadge.com/?utm_medium=github&utm_source=NetsoftHoldings&utm_campaign=badge_info)<!-- PR-BADGE: PLEASE DO NOT REMOVE THIS COMMENT -->

SyntaxError: Unexpected token ')''/red) Powered by Pull Request Badge

  1. PR Badge could have a dedicated facility for surfacing errors that occur during processing in a nice and clean way.
  2. PR Badge should probably ensure it correctly treats the input and output data at the correct level of injection and using the correct degree of escaping to avoid causing poor JavaScript to be generated or worse, permitting an unexpected degree of code injection. I suspect there are data injection issues at multiple levels going on here at the same time.
  3. It would be nice if there were facilities for dumping full objects, such as the $payload, for testing, but also to display or pass JSON on to eg. web requests. Ideally a message: $payload would just show me the full payload as a JSON string without any hoopla.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions