Skip to content

Commit 16f8001

Browse files
committed
Fix issues with bash quoting
1 parent a658692 commit 16f8001

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

content/reference/authentication/flows/password.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ Once you have been approved, using the password flow is pretty straightforward:
4949
&password=[user's password]
5050
&scope=[scopes separated by spaces]
5151

52-
> The use of `password_grant_secret` diverges from the OAuth 2.0 specificaion. `password_grant_secret` is a special token that we'll send you when your use of the password flow is approved.
52+
> The use of `password_grant_secret` diverges from the OAuth 2.0 specification. `password_grant_secret` is a special token that we'll send you when your use of the password flow is approved.
5353
54-
> **You can require app-specific passwords** by providing a `require_app_specific_password=1` URL parameter. **[Two-Factor Auth users](http://blog.app.net/2013/03/13/added-security-for-your-app-net-account/) must use app-specific passwords** irrespective of this parameter. We strongly encourage the use of app-specific passwords by all users as they significantly increase account security.
54+
> **You can require app-specific passwords** by providing a `require_app_specific_password=1` URL parameter. **[Two-Factor Auth users](http://blog.app.net/2013/03/13/added-security-for-your-app-net-account/) must use app-specific passwords** regardless of this parameter. We strongly encourage the use of app-specific passwords by all users as they significantly increase account security.
5555
5656
1. If the authorization was successful, App.net will respond with a JSON-encoded token:
5757

content/reference/authentication/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ When making a call to one of our API resources, there are three ways to include
133133

134134
* Add `access_token` to query string
135135

136-
<%= curl_example(:get, "posts/1?access_token=<YOUR ACCESS TOKEN>", :none, {:data => "text=Test post", :content_type => nil, :token => nil}) %>
136+
<%= curl_example(:get, "posts/1?access_token=<YOUR ACCESS TOKEN>", :none, {:data => {"text" => "Test post"}, :content_type => nil, :token => nil}) %>
137137

138138
* Add `access_token` to HTTP body.
139139

content/reference/resources/post/lifecycle.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ If you want to test how your text will be processed you can use the [text proces
2929
#### Example
3030

3131
<% text = get_hash(:post)["text"] %>
32-
<%= curl_example(:post, "posts", :post, {:data => "text=#{text}", :content_type => nil}) %>
32+
<%= curl_example(:post, "posts", :post, {:data => {"text" => text}, :content_type => nil}) %>
3333

3434
#### Example (JSON Data)
3535

lib/helpers.rb

+12-9
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ def access_token_banner()
9090
"<div class=\"alert alert-success alert-block authorize-prompt hide\"><p>#{login_url} to see more complete examples.</p></div>"
9191
end
9292

93+
def bash_quote(v)
94+
v.gsub('"', '\"')
95+
end
96+
9397
def curl_example(method, path, response_key, options = {}, &block)
9498
# things left to figure out
9599
# - some quoting/escaping stuff
@@ -167,24 +171,23 @@ def curl_example(method, path, response_key, options = {}, &block)
167171
if [:post, :put, :patch].include? method
168172
if not options[:data].empty?
169173
if options[:content_type] == "application/json"
170-
options[:data] = JSON.pretty_generate(options[:data])
171-
# todo: escape any single quotes in json data since we're about to wrap in single quotes for bash
172-
curl_parts << %{-d '#{options[:data]}'}
174+
data = bash_quote(JSON.pretty_generate(options[:data]))
175+
curl_parts << %{-d "#{data}"}
173176
elsif options[:data].instance_of? Hash
174177
options[:data].each do |k, v|
175-
curl_parts << %{-d '#{k}=#{v}'}
178+
val = bash_quote(v)
179+
curl_parts << %{-d "#{k}=#{val}"}
176180
end
177-
else
178-
# get rid of this case
179-
curl_parts << %{-d '#{options[:data]}'}
180181
end
181182
elsif options[:data_binary]
182-
curl_parts << %{--data-binary '#{options[:data_binary]}'}
183+
val = bash_quote(options[:data_binary])
184+
curl_parts << %{--data-binary "#{val}"}
183185
end
184186
end
185187

186188
options[:files].each do |k, v|
187-
curl_parts << %{-F "#{k}=#{v}"}
189+
val = bash_quote(v)
190+
curl_parts << %{-F "#{k}=#{val}"}
188191
end
189192

190193
if options[:stdin]

0 commit comments

Comments
 (0)