13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/media_types/serialization/serializers/input_validation_error_serializer.rb', line 13
def self.escape_text(text)
text
.split("\n")
.map { |l| CGI.escapeHTML(l).gsub(/ (?= )/, ' ') }
.map do |l|
l.gsub(/\bhttps?:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;{}]*[-A-Z0-9+@#\/%=}~_|](?![a-z]*;)/i) do |m|
converted = m
invalid = false
begin
converted = viewerify(m, context.request.host)
rescue URI::InvalidURIError
invalid = true
end
style = ''
style = ' style="color: red"' if invalid
"<a#{style} href=\"#{converted}\">#{m}</a>"
end
end
.join("<br>\n")
end
|