Sha256: 061638e83bde7452feddfe22f3d7f7a20238775e1d35b957a30a941aa7e60b4e

Contents?: true

Size: 1.5 KB

Versions: 5

Compression:

Stored size: 1.5 KB

Contents

# encoding: UTF-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')

describe EscapeUtils, "unescape_javascript" do
  it "should respond to unescape_javascript" do
    EscapeUtils.should respond_to(:unescape_javascript)
  end

  # these are from the ActionView tests
  it "should return an empty string if passed nil" do
    EscapeUtils.unescape_javascript(nil).should eql("")
  end

  it "should unescape quotes and newlines" do
    EscapeUtils.unescape_javascript(%(This \\"thing\\" is really\\n netos\\n\\n\\')).should eql(%(This "thing" is really\n netos\n\n'))
  end

  it "should unescape backslashes" do
    EscapeUtils.unescape_javascript(%(backslash\\\\test)).should eql(%(backslash\\test))
  end

  it "should unescape closed html tags" do
    EscapeUtils.unescape_javascript(%(dont <\\/close> tags)).should eql(%(dont </close> tags))
  end

  if RUBY_VERSION =~ /^1.9/
    it "should default to utf-8 if Encoding.default_internal is nil" do
      Encoding.default_internal = nil
      EscapeUtils.unescape_javascript(%(dont <\\/close> tags)).encoding.should eql(Encoding.find('utf-8'))
    end

    it "should use Encoding.default_internal" do
      Encoding.default_internal = Encoding.find('utf-8')
      EscapeUtils.unescape_javascript(%(dont <\\/close> tags)).encoding.should eql(Encoding.default_internal)
      Encoding.default_internal = Encoding.find('us-ascii')
      EscapeUtils.unescape_javascript(%(dont <\\/close> tags)).encoding.should eql(Encoding.default_internal)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
escape_utils-0.1.9 spec/javascript/unescape_spec.rb
escape_utils-0.1.8 spec/javascript/unescape_spec.rb
escape_utils-0.1.7 spec/javascript/unescape_spec.rb
escape_utils-0.1.6 spec/javascript/unescape_spec.rb
escape_utils-0.1.5 spec/javascript/unescape_spec.rb