require File.expand_path(File.dirname(__FILE__) + '../../spec_helper') module Owasp module Esapi module Codec describe HtmlCodec do let (:codec) { Owasp::Esapi::Codec::HtmlCodec.new } it "should not change test" do codec.encode([],"test").should == "test" end it "should encode < as <" do codec.encode([],"<").should == "<" end it "should encode 0x100 as Ā" do s = 0x100.chr(Encoding::UTF_8) m = codec.encode([],s[0]) m.should == "Ā" end it "should decode test! as test!" do codec.decode("test!").should == "test!" end it "should skip &jeff; an invlaid attribute" do codec.decode("&jeff;").should == "&jeff;" end # dynamic tests for various inputs to decode { "&" => "&", "&X" => "&X", "&" => "&", "&X" => "&X", "<" => "<", "<X" => " "<", "<X"=> " "<", "²" => "\u00B2", "²X" => "\u00B2X", "²" => "\u00B2", "²X" => "\u00B2X", "³" => "\u00B3", "³X" => "\u00B3X", "³" => "\u00B3", "³X" => "\u00B3X", "¹" => "\u00B9", "¹X" => "\u00B9X", "¹" => "\u00B9", "¹X" => "\u00B9X", "⊃" => "\u2283", "⊃X" => "\u2283X", "&sup" => "\u2283", "&supX" => "\u2283X", "⊇" => "\u2287", "⊇X" => "\u2287X", "&supe" => "\u2287", "&supeX" => "\u2287X", "π" => "\u03C0", "πX" => "\u03C0X", "&pi" => "\u03C0", "&piX" => "\u03C0X", "ϖ" => "\u03D6", "ϖX" => "\u03D6X", "&piv" => "\u03D6", "&pivX" => "\u03D6X", "θ" => "\u03B8", "θX" => "\u03B8X", "&theta" => "\u03B8", "&thetaX" => "\u03B8X", "ϑ" => "\u03D1", "ϑX" => "\u03D1X", "&thetasym" => "\u03D1", "&thetasymX" => "\u03D1X", }.each_pair do |k,v| it "should decode #{k} as #{v}" do codec.decode(k).should == v end end end end end end