mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Correctly escape category description text (#8107)
* FIX: Correctly escape category description text This bug has been introduced indb14e10943
. * Remove unnecessary `html_safe` `Theme.lookup_field` already returns html-safe strings:7ad338e3e6/app/models/theme.rb (L237-L242)
* Rename `description` where it's acutally `descriptionText`
This commit is contained in:
parent
f7923958e2
commit
d407bcab36
@ -75,7 +75,7 @@ export function categoryLinkHTML(category, options) {
|
|||||||
registerUnbound("category-link", categoryLinkHTML);
|
registerUnbound("category-link", categoryLinkHTML);
|
||||||
|
|
||||||
function defaultCategoryLinkRenderer(category, opts) {
|
function defaultCategoryLinkRenderer(category, opts) {
|
||||||
let description = get(category, "description_text");
|
let descriptionText = get(category, "description_text");
|
||||||
let restricted = get(category, "read_restricted");
|
let restricted = get(category, "read_restricted");
|
||||||
let url = opts.url
|
let url = opts.url
|
||||||
? opts.url
|
? opts.url
|
||||||
@ -121,7 +121,7 @@ function defaultCategoryLinkRenderer(category, opts) {
|
|||||||
'data-drop-close="true" class="' +
|
'data-drop-close="true" class="' +
|
||||||
classNames +
|
classNames +
|
||||||
'"' +
|
'"' +
|
||||||
(description ? 'title="' + escapeExpression(description) + '" ' : "") +
|
(descriptionText ? 'title="' + descriptionText + '" ' : "") +
|
||||||
">";
|
">";
|
||||||
|
|
||||||
let categoryName = escapeExpression(get(category, "name"));
|
let categoryName = escapeExpression(get(category, "name"));
|
||||||
|
@ -84,9 +84,9 @@ export default SelectKitRowComponent.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
@computed("category.description_text")
|
@computed("category.description_text")
|
||||||
descriptionText(description) {
|
descriptionText(descriptionText) {
|
||||||
if (description) {
|
if (descriptionText) {
|
||||||
return this._formatCategoryDescription(description);
|
return this._formatCategoryDescription(descriptionText);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -437,17 +437,14 @@ module ApplicationHelper
|
|||||||
|
|
||||||
def theme_lookup(name)
|
def theme_lookup(name)
|
||||||
Theme.lookup_field(theme_ids, mobile_view? ? :mobile : :desktop, name)
|
Theme.lookup_field(theme_ids, mobile_view? ? :mobile : :desktop, name)
|
||||||
&.html_safe
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def theme_translations_lookup
|
def theme_translations_lookup
|
||||||
Theme.lookup_field(theme_ids, :translations, I18n.locale)
|
Theme.lookup_field(theme_ids, :translations, I18n.locale)
|
||||||
&.html_safe
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def theme_js_lookup
|
def theme_js_lookup
|
||||||
Theme.lookup_field(theme_ids, :extra_js, nil)
|
Theme.lookup_field(theme_ids, :extra_js, nil)
|
||||||
&.html_safe
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def discourse_stylesheet_link_tag(name, opts = {})
|
def discourse_stylesheet_link_tag(name, opts = {})
|
||||||
|
@ -261,7 +261,8 @@ class Category < ActiveRecord::Base
|
|||||||
|
|
||||||
@@cache ||= LruRedux::ThreadSafeCache.new(1000)
|
@@cache ||= LruRedux::ThreadSafeCache.new(1000)
|
||||||
@@cache.getset(self.description) do
|
@@cache.getset(self.description) do
|
||||||
Nokogiri::HTML.fragment(self.description).text.strip.html_safe
|
text = Nokogiri::HTML.fragment(self.description).text.strip
|
||||||
|
Rack::Utils.escape_html(text).html_safe
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
<div class="dialog">
|
<div class="dialog">
|
||||||
<p>
|
<p>
|
||||||
<%=t "login.auth_complete" %>
|
<%=t "login.auth_complete" %>
|
||||||
<a href="<%= Discourse.base_url.html_safe %>?authComplete=true"><%= t("login.click_to_continue") %></a>
|
<a href="<%= Discourse.base_url %>?authComplete=true"><%= t("login.click_to_continue") %></a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
@ -14,4 +14,11 @@ describe CategoryBadge do
|
|||||||
expect(html).to include(ERB::Util.html_escape("<b>name</b>"))
|
expect(html).to include(ERB::Util.html_escape("<b>name</b>"))
|
||||||
expect(html).to include("title='title'")
|
expect(html).to include("title='title'")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "escapes code block contents" do
|
||||||
|
c = Fabricate(:category, description: '<code>\' <b id="x"></code>')
|
||||||
|
html = CategoryBadge.html_for(c)
|
||||||
|
|
||||||
|
expect(html).to include("title='' <b id="x">'")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -357,7 +357,7 @@ describe Category do
|
|||||||
c = Category.new
|
c = Category.new
|
||||||
expect(c.description_text).to be_nil
|
expect(c.description_text).to be_nil
|
||||||
c.description = "<hello <a>test</a>."
|
c.description = "<hello <a>test</a>."
|
||||||
expect(c.description_text).to eq("<hello test.")
|
expect(c.description_text).to eq("<hello test.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user