Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
escape the GrapeSwaggerRails.options hash properly in the template
  • Loading branch information
Eric Mueller committed Apr 27, 2016
commit 8fc397ab59da222b9699dc457f7630cd481edfc4
1 change: 1 addition & 0 deletions .ruby-gemset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grape-swagger-rails
2 changes: 1 addition & 1 deletion app/views/grape_swagger_rails/application/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html data-swagger-options="<%= GrapeSwaggerRails.options.marshal_dump.to_json %>">
<html data-swagger-options='<%== GrapeSwaggerRails.options.marshal_dump.to_json %>'>
<head>
<title><%= GrapeSwaggerRails.options.app_name || 'Swagger UI' %></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Expand Down
7 changes: 7 additions & 0 deletions spec/features/swagger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
before do
@options = GrapeSwaggerRails.options.dup
end

it 'evaluates config options correctly' do
visit '/swagger'
page_options_json = page.evaluate_script("$('html').data('swagger-options')").to_json
expect(page_options_json).to eq(@options.marshal_dump.to_json)
end
Copy link
Member

@dblock dblock Apr 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good spec, but it doesn't fail before the code change, you need another one that demonstrates the fix for the bug you're fixing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That one should have, I didn't realize that jquery unescapes html entities when processing a data tag. So there was no bug, except that the contents of the <html> tag were difficult to read.


context '#headers' do
before do
GrapeSwaggerRails.options.headers['X-Test-Header'] = 'Test Value'
Expand Down