Module: WEBrick::HTMLUtils

Defined in:
lib/webrick/htmlutils.rb

Class Method Summary collapse

Class Method Details

.escape(string) ⇒ Object

Escapes &, “, > and < in string



17
18
19
20
21
22
23
24
25
# File 'lib/webrick/htmlutils.rb', line 17

def escape(string)
  return "" unless string
  str = string.b
  str.gsub!(/&/n, '&amp;')
  str.gsub!(/\"/n, '&quot;')
  str.gsub!(/>/n, '&gt;')
  str.gsub!(/</n, '&lt;')
  str.force_encoding(string.encoding)
end