Skip to content

Commit

Permalink
Escape excerpt text by default (pat#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
edouard authored and pat committed Oct 10, 2009
1 parent c735141 commit ed2c514
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/thinking_sphinx.rb
Expand Up @@ -6,6 +6,7 @@
require 'riddle' require 'riddle'
require 'after_commit' require 'after_commit'
require 'yaml' require 'yaml'
require 'cgi'


require 'thinking_sphinx/core/array' require 'thinking_sphinx/core/array'
require 'thinking_sphinx/core/string' require 'thinking_sphinx/core/string'
Expand Down
2 changes: 1 addition & 1 deletion lib/thinking_sphinx/excerpter.rb
Expand Up @@ -14,7 +14,7 @@ def initialize(search, instance)
end end


def method_missing(method, *args, &block) def method_missing(method, *args, &block)
string = @instance.send(method, *args, &block).to_s string = CGI::escapeHTML @instance.send(method, *args, &block).to_s


@search.excerpt_for(string, @instance.class) @search.excerpt_for(string, @instance.class)
end end
Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/models.rb
Expand Up @@ -106,6 +106,10 @@ def big_name
name.upcase name.upcase
end end


def string_to_escape
'test "escaping" <characters>'
end

def sphinx_attributes def sphinx_attributes
:existing :existing
end end
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/thinking_sphinx/excerpter_spec.rb
Expand Up @@ -40,6 +40,14 @@
@excerpter.big_name @excerpter.big_name
end end


it "should escape the text in the excerpt" do
@search.should_receive(:excerpt_for) do |string, model|
string.should == 'test &quot;escaping&quot; &lt;characters&gt;'
end

@excerpter.string_to_escape
end

it "should still raise an exception if no column or method exists" do it "should still raise an exception if no column or method exists" do
lambda { lambda {
@excerpter.foo @excerpter.foo
Expand Down

0 comments on commit ed2c514

Please sign in to comment.