Class: Hanami::View::HTML::SafeString

Inherits:
String show all
Defined in:
lib/hanami/view/html.rb

Overview

A string that has been marked as "HTML safe", ensuring that it is not automatically escaped when used in HTML view templates.

A SafeString is frozen when initialized to ensure it cannot be mutated after being marked as safe, which could be an avenue for injection of unsafe content.

See Also:

  • String#html_safe

Since:

  • 2.1.0

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ SafeString

Returns a new instance of SafeString.

Since:

  • 2.1.0



23
24
25
26
# File 'lib/hanami/view/html.rb', line 23

def initialize(string)
  super(string)
  freeze
end

Instance Method Details

#html_safeself

Returns:

  • (self)

Since:

  • 2.1.0



47
48
49
# File 'lib/hanami/view/html.rb', line 47

def html_safe
  self
end

#html_safe?true

Returns:

  • (true)

Since:

  • 2.1.0



39
40
41
# File 'lib/hanami/view/html.rb', line 39

def html_safe?
  true
end

#to_sself

Returns:

  • (self)

Since:

  • 2.1.0



55
56
57
# File 'lib/hanami/view/html.rb', line 55

def to_s
  self
end