tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit fafdf7c7f6c35609309c6b7bd526f79c22e31b4a
parent fe64b1f2d549c58036c18fde759c79eba9baa367
Author: Morgan Rae Reschenberg <mreschenberg@berkeley.edu>
Date:   Wed,  1 Oct 2025 17:48:11 +0000

Bug 1990785: Verify text attributes exist before adding to them r=Jamie

Differential Revision: https://phabricator.services.mozilla.com/D266937

Diffstat:
Maccessible/mac/GeckoTextMarker.mm | 7+++++++
Maccessible/tests/browser/mac/browser_attributed_text.js | 32++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/accessible/mac/GeckoTextMarker.mm b/accessible/mac/GeckoTextMarker.mm @@ -429,6 +429,13 @@ static void AppendTextToAttributedString( static RefPtr<AccAttributes> GetTextAttributes(TextLeafPoint aPoint) { RefPtr<AccAttributes> attrs = aPoint.GetTextAttributes(); + if (!attrs) { + // If we can't fetch text attributes for the given point, return null. + // We avoid creating a new AccAttributes here because our AttributedText() + // code below relies on this null return value to indicate we're dealing + // with a non-text control. + return nullptr; + } // Mac expects some object properties to be exposed as text attributes. We // add these here rather than in utils::StringAttributesFromAccAttributes so // we can use AccAttributes::Equal to determine whether we need to start a new diff --git a/accessible/tests/browser/mac/browser_attributed_text.js b/accessible/tests/browser/mac/browser_attributed_text.js @@ -276,3 +276,35 @@ addAccessibleTask( ok(!attributedText[2].AXHighlight); } ); + +// Test the <mark> element, in conjunction with content that will +// prevent the creation of a text attributes object. +addAccessibleTask( + `<mark>a<button></button>b</mark>`, + async function testMarkNoAttributes(browser, accDoc) { + const macDoc = accDoc.nativeInterface.QueryInterface( + Ci.nsIAccessibleMacInterface + ); + const range = macDoc.getParameterizedAttributeValue( + "AXTextMarkerRangeForUnorderedTextMarkers", + [ + macDoc.getAttributeValue("AXStartTextMarker"), + macDoc.getAttributeValue("AXEndTextMarker"), + ] + ); + const attributedText = macDoc.getParameterizedAttributeValue( + "AXAttributedStringForTextMarkerRange", + range + ); + ok(attributedText, "Document has attributed text"); + is(attributedText.length, 3, "3 pieces of attributed text exist"); + + ok(attributedText[0].AXHighlight, "0th pos text has highlight"); + is(attributedText[0].string, "a", "0th pos text is string `a`"); + + ok(!attributedText[1].AXHighlight, "1st pos text has no highlight"); + + ok(attributedText[2].AXHighlight, "2nd pos text has highlight"); + is(attributedText[2].string, "b", "2nd pos text is string `b`"); + } +);