Skip to content

Data in cURL examples is not quoted properly #58

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

Closed
mindscratch opened this issue Mar 8, 2013 · 3 comments · Fixed by #60
Closed

Data in cURL examples is not quoted properly #58

mindscratch opened this issue Mar 8, 2013 · 3 comments · Fixed by #60

Comments

@mindscratch
Copy link

The cURL examples genreated when doing a POST or PUT don't properly quote the data associated with the -d flag.

For example, the rad-example app has the following cURL example for creating an order:

curl "http://rad-example.herokuapp.com/orders" -d "{"order":{"name":"Order 1","paid":true,"email":"[email protected]"}}" -X POST -H "Accept: application/json" -H "Content-Type: application/json" -H "Host: example.org" -H "Cookie: "

source: http://rad-example.herokuapp.com/docs/orders/creating_an_order

If you copy/paste that example it'll fail because the data uses all double quotes. Instead the outer quotes should be single quotes such as:

-d '{"order":{"name":"Order 1","paid":true,"email":"[email protected]"}}'
@mindscratch
Copy link
Author

If I was at home, I'd fork and fix it but I believe the double-quotes here just need to be changed to single quotes.

@mrbrdo
Copy link
Contributor

mrbrdo commented Mar 13, 2013

Temporary fix, put this into spec/support/api_doc.rb

RspecApiDocumentation::Curl # force autoload
module RspecApiDocumentation
  class Curl
    def post_data
      escaped_data = data.gsub('"', '\\"')
      "-d \"#{escaped_data}\""
    end
  end
end

This should be updated, I ran into this issue as well.
This is better than using single quotes since then you'd have to escape the single quotes anyway.

@mrbrdo
Copy link
Contributor

mrbrdo commented Mar 19, 2013

A little better, quote in single quotes and escape any single quote (can't use ', but \u0027 works).

RspecApiDocumentation::Curl
module RspecApiDocumentation
  class Curl
    def post_data
      escaped_data = data.gsub("'", "\\u0027")
      "-d '#{escaped_data}'"
    end
  end
end

@mrbrdo mrbrdo mentioned this issue Mar 19, 2013
tmk-kwmr pushed a commit to tmk-kwmr/rspec_api_doc_test that referenced this issue Sep 8, 2014
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 a pull request may close this issue.

3 participants