mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-04 13:28:25 +00:00 
			
		
		
		
	Forbid HTML injection using jQuery (#29843)
See https://github.com/wikimedia/eslint-plugin-no-jquery/blob/master/docs/rules/no-append-html.md Tested the following components and they work as before: - notification table - issue author dropdown - comment edit box attachments div Signed-off-by: Yarden Shoham <git@yardenshoham.com> Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
		@@ -143,8 +143,8 @@ async function updateNotificationCountWithCallback(callback, timeout, lastCount)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function updateNotificationTable() {
 | 
			
		||||
  const $notificationDiv = $('#notification_div');
 | 
			
		||||
  if ($notificationDiv.length > 0) {
 | 
			
		||||
  const notificationDiv = document.getElementById('notification_div');
 | 
			
		||||
  if (notificationDiv) {
 | 
			
		||||
    try {
 | 
			
		||||
      const params = new URLSearchParams(window.location.search);
 | 
			
		||||
      params.set('div-only', true);
 | 
			
		||||
@@ -158,7 +158,7 @@ async function updateNotificationTable() {
 | 
			
		||||
 | 
			
		||||
      const data = await response.text();
 | 
			
		||||
      if ($(data).data('sequence-number') === notificationSequenceNumber) {
 | 
			
		||||
        $notificationDiv.replaceWith(data);
 | 
			
		||||
        notificationDiv.outerHTML = data;
 | 
			
		||||
        initNotificationsTable();
 | 
			
		||||
      }
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
 
 | 
			
		||||
@@ -125,7 +125,9 @@ function initRepoIssueListAuthorDropdown() {
 | 
			
		||||
    if (newMenuHtml) {
 | 
			
		||||
      const $newMenuItems = $(newMenuHtml);
 | 
			
		||||
      $newMenuItems.addClass('dynamic-item');
 | 
			
		||||
      $menu.append('<div class="divider dynamic-item"></div>', ...$newMenuItems);
 | 
			
		||||
      const div = document.createElement('div');
 | 
			
		||||
      div.classList.add('divider', 'dynamic-item');
 | 
			
		||||
      $menu[0].append(div, ...$newMenuItems);
 | 
			
		||||
    }
 | 
			
		||||
    $searchDropdown.dropdown('refresh');
 | 
			
		||||
    // defer our selection to the next tick, because dropdown will set the selection item after this `menu` function
 | 
			
		||||
 
 | 
			
		||||
@@ -436,13 +436,12 @@ async function onEditContent(event) {
 | 
			
		||||
      const $content = $segment;
 | 
			
		||||
      if (!$content.find('.dropzone-attachments').length) {
 | 
			
		||||
        if (data.attachments !== '') {
 | 
			
		||||
          $content.append(`<div class="dropzone-attachments"></div>`);
 | 
			
		||||
          $content.find('.dropzone-attachments').replaceWith(data.attachments);
 | 
			
		||||
          $content[0].append(data.attachments);
 | 
			
		||||
        }
 | 
			
		||||
      } else if (data.attachments === '') {
 | 
			
		||||
        $content.find('.dropzone-attachments').remove();
 | 
			
		||||
      } else {
 | 
			
		||||
        $content.find('.dropzone-attachments').replaceWith(data.attachments);
 | 
			
		||||
        $content.find('.dropzone-attachments')[0].outerHTML = data.attachments;
 | 
			
		||||
      }
 | 
			
		||||
      if (dz) {
 | 
			
		||||
        dz.emit('submit');
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user