Move unescape_html_entities
from LabelsHelper to Label model
This commit is contained in:
parent
ab811b6ab9
commit
d6b60e83ed
4 changed files with 13 additions and 19 deletions
|
@ -1,12 +1,6 @@
|
|||
module LabelsHelper
|
||||
include ActionView::Helpers::TagHelper
|
||||
|
||||
TABLE_FOR_ESCAPE_HTML_ENTITIES = {
|
||||
'&' => '&',
|
||||
'<' => '<',
|
||||
'>' => '>'
|
||||
}
|
||||
|
||||
# Link to a Label
|
||||
#
|
||||
# label - Label object to link to
|
||||
|
@ -136,11 +130,7 @@ module LabelsHelper
|
|||
label.subscribed?(current_user) ? 'Unsubscribe' : 'Subscribe'
|
||||
end
|
||||
|
||||
def unescape_html_entities(value)
|
||||
value.to_s.gsub(/(>)|(<)|(&)/, TABLE_FOR_ESCAPE_HTML_ENTITIES.invert)
|
||||
end
|
||||
|
||||
# Required for Banzai::Filter::LabelReferenceFilter
|
||||
module_function :render_colored_label, :render_colored_cross_project_label,
|
||||
:text_color_for_bg, :escape_once, :unescape_html_entities
|
||||
:text_color_for_bg, :escape_once
|
||||
end
|
||||
|
|
|
@ -10,6 +10,12 @@ class Label < ActiveRecord::Base
|
|||
|
||||
DEFAULT_COLOR = '#428BCA'
|
||||
|
||||
TABLE_FOR_ESCAPE_HTML_ENTITIES = {
|
||||
'&' => '&',
|
||||
'<' => '<',
|
||||
'>' => '>'
|
||||
}
|
||||
|
||||
default_value_for :color, DEFAULT_COLOR
|
||||
|
||||
belongs_to :project
|
||||
|
@ -134,6 +140,10 @@ class Label < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def sanitize_title(value)
|
||||
LabelsHelper.unescape_html_entities(Sanitize.clean(value.to_s))
|
||||
unescape_html_entities(Sanitize.clean(value.to_s))
|
||||
end
|
||||
|
||||
def unescape_html_entities(value)
|
||||
value.to_s.gsub(/(>)|(<)|(&)/, TABLE_FOR_ESCAPE_HTML_ENTITIES.invert)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -68,7 +68,7 @@ module Banzai
|
|||
end
|
||||
|
||||
def unescape_html_entities(text)
|
||||
LabelsHelper.unescape_html_entities(text)
|
||||
text.to_s.gsub(/(>)|(<)|(&)/, Label::TABLE_FOR_ESCAPE_HTML_ENTITIES.invert)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -77,10 +77,4 @@ describe LabelsHelper do
|
|||
expect(text_color_for_bg('#000')).to eq '#FFFFFF'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'unescape_html_entities' do
|
||||
it 'decodes &, <, and > named entities' do
|
||||
expect(unescape_html_entities('foo & bar < zoo > boo é')).to eq 'foo & bar < zoo > boo é'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue