Bug 1679075 - Don't go past empty input field in HyperTextIterator::Next. r=morgan

The normalize function was putting the current container/offset past the end boundary. This caused overruns with getting the text for the range of the input object, and some unexpected invalid ranges.

Differential Revision: https://phabricator.services.mozilla.com/D98236
This commit is contained in:
Eitan Isaacson 2020-11-30 20:46:15 +00:00
parent f6cf2a4d4c
commit c86df09ea1
3 changed files with 36 additions and 4 deletions

View File

@ -79,6 +79,12 @@ bool HyperTextIterator::NormalizeForward() {
mCurrentContainer = mCurrentContainer->Parent()->AsHyperText();
mCurrentStartOffset = endOffset;
if (mCurrentContainer == mEndContainer &&
mCurrentStartOffset >= mEndOffset) {
// Reached end boundary.
return false;
}
// Call NormalizeForward recursively to get top-most link if at the end of
// one, or innermost link if at the beginning.
NormalizeForward();
@ -98,6 +104,12 @@ bool HyperTextIterator::NormalizeForward() {
mCurrentStartOffset = 0;
}
if (mCurrentContainer == mEndContainer &&
mCurrentStartOffset >= mEndOffset) {
// Reached end boundary.
return false;
}
// Call NormalizeForward recursively to get top-most embedding ancestor
// if at the end of one, or innermost link if at the beginning.
NormalizeForward();

View File

@ -171,10 +171,8 @@ inline NSString* ToNSString(id aValue) {
return nil;
}
GeckoTextMarker startMarker =
GeckoTextMarker::MarkerFromIndex(mGeckoAccessible, 0);
GeckoTextMarkerRange fromStartToSelection(startMarker, selection.mStart);
GeckoTextMarkerRange fromStartToSelection(
GeckoTextMarker(mGeckoAccessible, 0), selection.mStart);
return [NSValue valueWithRange:NSMakeRange(fromStartToSelection.Length(),
selection.Length())];
@ -268,6 +266,10 @@ inline NSString* ToNSString(id aValue) {
- (NSString*)moxStringForRange:(NSValue*)range {
GeckoTextMarkerRange markerRange = [self textMarkerRangeFromRange:range];
if (!markerRange.IsValid()) {
return nil;
}
return markerRange.Text();
}

View File

@ -245,3 +245,21 @@ addAccessibleTask(
is(stringForRange(macDoc, range), "ello good");
}
);
addAccessibleTask(
`<input id="input" value=""><a href="#">goodbye</a>`,
async (browser, accDoc) => {
let macDoc = accDoc.nativeInterface.QueryInterface(
Ci.nsIAccessibleMacInterface
);
let input = getNativeInterface(accDoc, "input");
let range = macDoc.getParameterizedAttributeValue(
"AXTextMarkerRangeForUIElement",
input
);
is(stringForRange(macDoc, range), "", "string value is correct");
}
);