Skip to content

Commit

Permalink
Use unescaped URL and unescape HTML entities.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmycuadra committed Feb 27, 2014
1 parent 09d2754 commit 14d3ee1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lib/lita/handlers/google.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require "cgi"
require "uri"

require "lita"

module Lita
Expand Down Expand Up @@ -28,7 +31,9 @@ def search(response)
result = data["responseData"]["results"].first

if result
response.reply("#{result["titleNoFormatting"]} - #{result["url"]}")
response.reply(
"#{CGI.unescapeHTML(result["titleNoFormatting"])} - #{result["unescapedUrl"]}"
)
else
response.reply("No search results for query: #{query}")
end
Expand Down
6 changes: 3 additions & 3 deletions spec/lita/handlers/google_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
{
"responseData": {
"results": [{
"url": "https://www.ruby-lang.org/",
"titleNoFormatting": "Ruby Programming Language"
"unescapedUrl": "http://www.youtube.com/watch?v=EwTZ2xpQwpA",
"titleNoFormatting": ""Chocolate Rain" Original Song by Tay Zonday"
}]
}
}
Expand All @@ -34,7 +34,7 @@
send_command("google ruby")

expect(replies.last).to eq(
"Ruby Programming Language - https://www.ruby-lang.org/"
%{"Chocolate Rain" Original Song by Tay Zonday - http://www.youtube.com/watch?v=EwTZ2xpQwpA}
)
end

Expand Down

0 comments on commit 14d3ee1

Please sign in to comment.