Skip to content
Snippets Groups Projects

Escape arguments to curl

Merged Warren Gifford requested to merge shell-escape into master

Created by: chrismwendt

Previously, whitespace in the GraphQL input could get compressed away.

curl commands now look like this:

curl \
   -H 'Authorization: token abcdef' \
   -d \{\"query\":\"query {  currentUser { username } }\",\"variables\":\{}} \
   sourcegraph.com/.api/graphql

Merge request reports

Merged by avatar (Jul 9, 2025 7:21am UTC)

Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Created by: slimsag

    Question about your solution here: prior to this change running this command:

    echo 'query($query: String!) {                                                                                                                                   
      search(query: $query) {
        results {
          resultCount
        }
      }
    }' | src api -vars '{"query": "abc"}' --get-curl 'query=abc=foo' 'foo=bar'

    Would produce:

    curl \
       -H 'Authorization: token <redacted>' \
       -d '{"query":"query($query: String!) { search(query: $query) { results { resultCount } } }","variables":{"foo":"bar","query":"abc=foo"}}' \
       https://sourcegraph.com/.api/graphql

    Now it produces (very long line, see horizontal scrollbar):

    curl \
       -H 'Authorization: token <redacted>' \
       -d '{"query":"query($query: String!) {                                                                                                                                   \n  search(query: $query) {\n    results {\n      resultCount\n    }\n  }\n}\n","variables":{"foo":"bar","query":"abc=foo"}}' \
       https://sourcegraph.com/.api/graphql
  • Created by: chrismwendt

    Yeah, unfortunately there is no golang implementation of GraphQL minification (there's a Node.js one https://github.com/rse/graphql-query-compress).

    There appears to be a bunch of trailing whitespace on the first line of your query, in particular.

  • Created by: slimsag

    Yeah actually you are right, I had missed the case where someone might have a literal " whitespace " in their query which would get minified away by my naive implementation. This is much more correct

  • Created by: slimsag

    Review: Approved

  • Merged by: slimsag at 2018-04-24 22:06:30 UTC

Please register or sign in to reply
Loading