Ruby Building Web Apps with Sinatra Finishing Touches Summary

Rack::Utils.escape_html(string) does not work as described in the teacher's notes

When adding the following to my wiki.rb file:

def escape(string)

And adding the following in my show.erb file:

<p><%= escape @content %></p>

When adding the following content when creating a new page:


My results were the following:


Shouldn't this have rendered as <script>alert('boo');</script>, but with the HTML entities escaped?

1 Answer

Jay McGavren
Jay McGavren
Treehouse Teacher

Hmm, that's true! Another method (that's meant for escaping special characters in URLs) is overriding the escape method.

Looks like the fix is just to re-name the method we add to wiki.rb. I went with a method name of h (as in "HTML"):

def h(string)

I've updated the teacher's notes to reflect this. Sorry for the confusion!