Skip to content

Improve HTML escaping helper #12562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"cssnano": "4.1.10",
"domino": "2.1.5",
"dropzone": "5.7.0",
"escape-goat": "3.0.0",
"fast-glob": "3.2.2",
"file-loader": "6.0.0",
"fomantic-ui": "2.8.4",
Expand Down
17 changes: 7 additions & 10 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import './publicpath.js';
import './polyfills.js';

import Vue from 'vue';
import {htmlEscape} from 'escape-goat';
import 'jquery.are-you-sure';
import './vendor/semanticdropdown.js';
import {svg} from './utils.js';
Expand All @@ -25,10 +26,6 @@ import {createCodeEditor} from './features/codeeditor.js';

const {AppSubUrl, StaticUrlPrefix, csrf} = window.config;

function htmlEncode(text) {
return jQuery('<div />').text(text).html();
}

let previewFileModes;
const commentMDEditors = {};

Expand Down Expand Up @@ -532,12 +529,12 @@ function initCommentForm() {
switch (input_id) {
case '#milestone_id':
$list.find('.selected').html(`<a class="item" href=${$(this).data('href')}>${
htmlEncode($(this).text())}</a>`);
htmlEscape($(this).text())}</a>`);
break;
case '#assignee_id':
$list.find('.selected').html(`<a class="item" href=${$(this).data('href')}>` +
`<img class="ui avatar image" src=${$(this).data('avatar')}>${
htmlEncode($(this).text())}</a>`);
htmlEscape($(this).text())}</a>`);
}
$(`.ui${select_id}.list .no-select`).addClass('hide');
$(input_id).val($(this).data('id'));
Expand Down Expand Up @@ -1942,7 +1939,7 @@ function searchUsers() {
$.each(response.data, (_i, item) => {
let title = item.login;
if (item.full_name && item.full_name.length > 0) {
title += ` (${htmlEncode(item.full_name)})`;
title += ` (${htmlEscape(item.full_name)})`;
}
items.push({
title,
Expand Down Expand Up @@ -2223,7 +2220,7 @@ function initTemplateSearch() {
// Parse the response from the api to work with our dropdown
$.each(response.data, (_r, repo) => {
filteredResponse.results.push({
name: htmlEncode(repo.full_name),
name: htmlEscape(repo.full_name),
value: repo.id
});
});
Expand Down Expand Up @@ -3500,8 +3497,8 @@ function initIssueList() {
return;
}
filteredResponse.results.push({
name: `#${issue.number} ${htmlEncode(issue.title)
}<div class="text small dont-break-out">${htmlEncode(issue.repository.full_name)}</div>`,
name: `#${issue.number} ${htmlEscape(issue.title)
}<div class="text small dont-break-out">${htmlEscape(issue.repository.full_name)}</div>`,
value: issue.id
});
});
Expand Down