From 40a355a42d4a9444dc753c04c6608dade2f06a23 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:27 +0200 Subject: Adding upstream version 125.0.1. Signed-off-by: Daniel Baumann --- dom/base/IDTracker.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'dom/base/IDTracker.cpp') diff --git a/dom/base/IDTracker.cpp b/dom/base/IDTracker.cpp index 4db592534d..813aa44e11 100644 --- a/dom/base/IDTracker.cpp +++ b/dom/base/IDTracker.cpp @@ -132,13 +132,30 @@ void IDTracker::ResetWithLocalRef(Element& aFrom, const nsAString& aLocalRef, bool aWatch) { MOZ_ASSERT(nsContentUtils::IsLocalRefURL(aLocalRef)); - nsAutoCString ref; - if (!AppendUTF16toUTF8(Substring(aLocalRef, 1), ref, mozilla::fallible)) { + auto ref = Substring(aLocalRef, 1); + if (ref.IsEmpty()) { Unlink(); return; } - NS_UnescapeURL(ref); - RefPtr idAtom = NS_Atomize(ref); + + nsAutoCString utf8Ref; + if (!AppendUTF16toUTF8(ref, utf8Ref, mozilla::fallible)) { + Unlink(); + return; + } + + // Only unescape ASCII characters; if we were to unescape arbitrary bytes, + // we'd potentially end up with invalid UTF-8. + nsAutoCString unescaped; + bool appended; + if (NS_FAILED(NS_UnescapeURL(utf8Ref.BeginReading(), utf8Ref.Length(), + esc_OnlyASCII | esc_AlwaysCopy, unescaped, + appended, mozilla::fallible))) { + Unlink(); + return; + } + + RefPtr idAtom = NS_Atomize(unescaped); ResetWithID(aFrom, idAtom, aWatch); } -- cgit v1.2.3