Skip to content

Escape arguments to curl#1

Merged
emidoots merged 1 commit into
masterfrom
shell-escape
Apr 24, 2018
Merged

Escape arguments to curl#1
emidoots merged 1 commit into
masterfrom
shell-escape

Conversation

@chrismwendt

@chrismwendt chrismwendt commented Apr 24, 2018

Copy link
Copy Markdown
Contributor

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

@emidoots

Copy link
Copy Markdown
Member

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

@chrismwendt

Copy link
Copy Markdown
Contributor Author

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.

@emidoots

Copy link
Copy Markdown
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants