File: html_safety_test.rb

package info (click to toggle)
ruby-escape-utils 1.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 372 kB
  • sloc: ansic: 1,742; ruby: 1,079; sh: 7; makefile: 2
file content (46 lines) | stat: -rw-r--r-- 801 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require File.expand_path("../helper", __FILE__)

class Object
  def html_safe?
    false
  end
end

class TestSafeBuffer < String
  def html_safe?
    true
  end

  def html_safe
    self
  end

  def to_s
    self
  end
end

class String
  def html_safe
    TestSafeBuffer.new(self)
  end
end

class HtmlEscapeTest < Minitest::Test
  include EscapeUtils::HtmlSafety

  def test_marks_escaped_strings_safe
    escaped = _escape_html("<strong>unsafe</strong>")
    assert_equal "&lt;strong&gt;unsafe&lt;&#47;strong&gt;", escaped
    assert escaped.html_safe?
  end

  def test_doesnt_escape_safe_strings
    assert_equal "<p>safe string</p>", _escape_html("<p>safe string</p>".html_safe)
  end

  def test_
    assert_equal "5", _escape_html(5)
    assert_equal "hello", _escape_html(:hello)
  end
end