# encoding: utf-8 require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe Sanitizer do describe "sanitize" do it "should strip all tags" do html = "

Oi como Vai

" output = Sanitizer.sanitize(html) output.should == 'Oi como Vai' end it "should still clean even after multiple sanitizes" do html = "
Eu & você como Vai

" output = Sanitizer.sanitize(html) output = Sanitizer.sanitize(output) output = Sanitizer.sanitize(output) output.should == 'Eu & você como Vai' end it "should not break “ entities" do html = "“ Testando" output = Sanitizer.sanitize(html) output.should == "“ Testando" end it "should clean spaces and tags" do html = "

Oi como Vai

" output = Sanitizer.sanitize(html) output.should == 'Oi como Vai' end it "should clean '&' entries" do html = "Eu & você" output = Sanitizer.sanitize(html) output.should == "Eu & você" end it "should not remove valid entries" do html = "Eu & você" output = Sanitizer.sanitize(html) output.should == "Eu & você" end it "should clean '&' entries even when it is attached to a letter" do html = "M&M" output = Sanitizer.sanitize(html) output.should == "M&M" end end describe "html_encode" do it "should convert invalid chars to html entries" do text = "João foi caçar" output = Sanitizer.html_encode(text) output.should == "João foi caçar" end it "should sanitize HTML tags" do text = "

João foi caçar

" output = Sanitizer.html_encode(text) output.should == "<p>João <b>foi</b> caçar</p>" end end describe "strip_tags" do it "should remove only tags" do html = "

Oi como Vai

" output = Sanitizer.strip_tags(html, 'b') output.should == "

Oi como Vai

" end it "should remove only and tags" do html = "

Oi como Vai

" output = Sanitizer.strip_tags(html, 'a', 'b') output.should == "

Oi como Vai

" end end end