Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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)
  Rack::Utils.escape_html(string)
end

And adding the following in my show.erb file:

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

When adding the following content when creating a new page:

<script>alert('boo');</script>

My results were the following:

%3Cscript%3Ealert%28%27boo%27%29%3B%3C%2Fscript%3E

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

1 Answer

Jay McGavren
STAFF
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)
  Rack::Utils.escape_html(string)
end

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