2017-01-03 05:27:12 +08:00
|
|
|
module InputSanitizeHelper
|
2017-01-26 17:46:58 +08:00
|
|
|
def sanitize_input(
|
|
|
|
text,
|
|
|
|
tags = [],
|
|
|
|
attributes = []
|
|
|
|
)
|
2017-01-05 22:33:41 +08:00
|
|
|
ActionController::Base.helpers.sanitize(
|
|
|
|
text,
|
2017-01-26 17:46:58 +08:00
|
|
|
tags: Constants::WHITELISTED_TAGS + tags,
|
|
|
|
attributes: Constants::WHITELISTED_ATTRIBUTES + attributes
|
2017-01-05 22:33:41 +08:00
|
|
|
)
|
2017-01-03 05:27:12 +08:00
|
|
|
end
|
2017-01-05 19:51:14 +08:00
|
|
|
|
|
|
|
def escape_input(text)
|
|
|
|
ERB::Util.html_escape(text)
|
|
|
|
end
|
2017-01-12 00:02:17 +08:00
|
|
|
|
2017-04-19 15:11:52 +08:00
|
|
|
def custom_auto_link(text, options = {})
|
2017-05-09 17:25:00 +08:00
|
|
|
simple_f = options.fetch(:simple_format) { true }
|
|
|
|
team = options.fetch(:team) { nil }
|
2017-04-19 15:11:52 +08:00
|
|
|
wrapper_tag = options.fetch(:wrapper_tag) { {} }
|
|
|
|
tags = options.fetch(:tags) { [] }
|
2017-05-09 17:25:00 +08:00
|
|
|
fromat_opt = wrapper_tag.merge(sanitize: false)
|
|
|
|
text = sanitize_input(text, tags)
|
|
|
|
text = simple_format(sanitize_input(text), {}, fromat_opt) if simple_f
|
2017-01-24 23:44:56 +08:00
|
|
|
auto_link(
|
2017-04-19 15:11:52 +08:00
|
|
|
smart_annotation_parser(text, team),
|
2017-01-24 23:44:56 +08:00
|
|
|
link: :urls,
|
|
|
|
sanitize: false,
|
|
|
|
html: { target: '_blank' }
|
|
|
|
).html_safe
|
2017-01-12 00:02:17 +08:00
|
|
|
end
|
2017-01-03 05:27:12 +08:00
|
|
|
end
|