Sha256: 06ba0f1c154cdaa886d211b85d8512dd74a66eeac625a44cac881326b74ec39e

Contents?: true

Size: 1.98 KB

Versions: 5

Compression:

Stored size: 1.98 KB

Contents

# encoding: UTF-8
#
# Copyright (C) 2013 Wayne Meissner
#
# This file is part of the Walters project (http://github.com/wmeissner/walters).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This file contains code based on the EscapeUtils project.  See the file LICENSE-EscapeUtils.txt for details.  
#

require File.expand_path('../../spec_helper.rb', __FILE__)

describe 'html escape' do
  it 'double quotes' do
    Walters.escape_html("<some_tag some_attr=\"some value\"/>").should == '&lt;some_tag some_attr=&quot;some value&quot;&#47;&gt;'
  end

  it 'single quotes' do
    Walters.escape_html("<some_tag some_attr='some value'/>").should == '&lt;some_tag some_attr=&#39;some value&#39;&#47;&gt;'
  end

  it 'ampersand' do
    Walters.escape_html('<b>Bourbon & Branch</b>').should == '&lt;b&gt;Bourbon &amp; Branch&lt;&#47;b&gt;'
  end

  it 'original returned if no escaping required' do
    str = 'foobar'
    Walters.escape_html(str).should equal str
  end
  
  it 'all tags escaped' do 
    Walters.escape_html('&<>"\'/').should == '&amp;&lt;&gt;&quot;&#39;&#47;'
  end

  it 'plain text followed by tag' do
    Walters.escape_html('foobar<1>').should == 'foobar&lt;1&gt;'
  end

  it 'non-utf8 input' do
    lambda { Walters.escape_html('<b>Bourbon & Branch</b>'.encode('ISO-8859-1')) }.should raise_error Encoding::CompatibilityError
  end
  
  it 'returned value has same encoding as original' do
    str = '<b>Bourbon & Branch</b>'.encode('utf-8')
    Walters.escape_html(str).encoding.should == str.encoding
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
walters-0.2.0-java spec/walters/html_escape_spec.rb
walters-0.2.0 spec/walters/html_escape_spec.rb
walters-0.1.1 spec/walters/html_escape_spec.rb
walters-0.1.0-java spec/walters/html_escape_spec.rb
walters-0.1.0 spec/walters/html_escape_spec.rb