Skip to content

Commit deed309

Browse files
committed
Fix render bug for HTML translations in the bulk adding view
Previously in case the translation strings contained HTML, the HTML was not escaped in the bulk adding view.
1 parent 0369497 commit deed309

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

app/assets/javascripts/decidim/term_customizer/admin/translations_admin.js.es6

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ $(() => {
3232
const re = new RegExp(`(${sanitizedSearch.split(" ").join("|")})`, "gi");
3333
const modelId = item[0];
3434
const title = item[1];
35+
// The terms are already escaped but when they are rendered to a data
36+
// attribute, they get unescaped when those values are used. The only
37+
// character we need to replace is the ampersand
38+
const value = title.replace(/&/g, "&");
39+
3540
const val = `${title} - ${modelId}`;
36-
return `<div class="autocomplete-suggestion" data-model-id="${modelId}" data-val="${title}">${val.replace(re, "<b>$1</b>")}</div>`;
41+
return `<div class="autocomplete-suggestion" data-model-id="${modelId}" data-val="${value}">${val.replace(re, "<b>$1</b>")}</div>`;
3742
},
3843
onSelect: function(event, term, item) {
3944
const $suggestions = $search.data("sc");

app/controllers/decidim/term_customizer/admin/add_translations_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def search
4141
translations = directory.translations_search(params[:term])
4242
translations.reject! { |k| reject_keys.include?(k) }
4343

44-
render json: translations.map { |k, v| [k, v] }
44+
render json: translations.map { |k, v| [k, ERB::Util.html_escape(v)] }
4545
end
4646

4747
private

0 commit comments

Comments
 (0)