From 6cd95507fd1c8b47e51ac0cd23b910c73c6173af Mon Sep 17 00:00:00 2001 From: Chandra ObulaReddy <53801679+ChandraChaan@users.noreply.github.com> Date: Thu, 12 Nov 2026 06:53:13 +0530 Subject: [PATCH] fix(http): decode HTML entities in filenames in one pass (#1651) unescapeHTMLEntities applied its replacements while ranging over a map, so the order changed from run to run. An escaped ampersand such as "a&lt;b.txt" came out as "a<b.txt" or, when & was replaced first, as the double-decoded "a", + """, "\"", + "'", "'", + "'", "'", +) + // unescapeHTMLEntities unescapes common HTML entities in filenames // This handles cases where servers HTML-encode special characters like & to & func unescapeHTMLEntities(s string) string { - // Common HTML entities that might appear in filenames - replacements := map[string]string{ - "&": "&", - "<": "<", - ">": ">", - """: "\"", - "'": "'", - "'": "'", - } - - result := s - for entity, char := range replacements { - result = strings.ReplaceAll(result, entity, char) - } - return result + return htmlEntityReplacer.Replace(s) } // tryDecodeGBK attempts to decode string as GBK encoding