mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Merge pull request #2277 from vikhyat/fix-title-html
Fix HTML tags in topic titles
This commit is contained in:
@@ -61,7 +61,7 @@ Handlebars.registerHelper('shorten', function(property, options) {
|
||||
**/
|
||||
Handlebars.registerHelper('topicLink', function(property, options) {
|
||||
var topic = Ember.Handlebars.get(this, property, options),
|
||||
title = topic.get('fancy_title') || topic.get('title');
|
||||
title = topic.get('fancy_title');
|
||||
return "<a href='" + topic.get('lastUnreadUrl') + "' class='title'>" + title + "</a>";
|
||||
});
|
||||
|
||||
|
||||
@@ -65,7 +65,6 @@ class Topic < ActiveRecord::Base
|
||||
|
||||
|
||||
before_validation do
|
||||
self.sanitize_title
|
||||
self.title = TextCleaner.clean_title(TextSentinel.title_sentinel(title).text) if errors[:title].empty?
|
||||
end
|
||||
|
||||
@@ -242,17 +241,21 @@ class Topic < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def fancy_title
|
||||
return title unless SiteSetting.title_fancy_entities?
|
||||
sanitized_title = title.gsub(/['&\"<>]/, {
|
||||
"'" => ''',
|
||||
'&' => '&',
|
||||
'"' => '"',
|
||||
'<' => '<',
|
||||
'>' => '>',
|
||||
})
|
||||
|
||||
return sanitized_title unless SiteSetting.title_fancy_entities?
|
||||
|
||||
# We don't always have to require this, if fancy is disabled
|
||||
# see: http://meta.discourse.org/t/pattern-for-defer-loading-gems-and-profiling-with-perftools-rb/4629
|
||||
require 'redcarpet' unless defined? Redcarpet
|
||||
|
||||
Redcarpet::Render::SmartyPants.render(title)
|
||||
end
|
||||
|
||||
def sanitize_title
|
||||
self.title = sanitize(title.to_s, tags: [], attributes: []).strip.presence
|
||||
Redcarpet::Render::SmartyPants.render(sanitized_title)
|
||||
end
|
||||
|
||||
def new_version_required?
|
||||
|
||||
Reference in New Issue
Block a user