tor-browser

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

commit 3c4c3d7c9aa369df019fcc1e74f27b247e5c8157
parent ab69e32e0298c7d364622be19d65a8b85a182264
Author: Jan-Niklas Jaeschke <jjaschke@mozilla.com>
Date:   Sun, 19 Oct 2025 17:56:24 +0000

Bug 1951607 - nsFind should find <options> inside an <optgroup>. r=emilio

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

Diffstat:
Mdom/html/HTMLOptionElement.cpp | 2+-
Mdom/html/HTMLOptionElement.h | 13++++++-------
Mtoolkit/components/find/nsFind.cpp | 2+-
Mtoolkit/components/find/test/mochitest/test_nsFind.html | 11+++++++++++
4 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/dom/html/HTMLOptionElement.cpp b/dom/html/HTMLOptionElement.cpp @@ -254,7 +254,7 @@ void HTMLOptionElement::UnbindFromTree(UnbindContext& aContext) { } // Get the select content element that contains this option -HTMLSelectElement* HTMLOptionElement::GetSelect() { +HTMLSelectElement* HTMLOptionElement::GetSelect() const { nsIContent* parent = GetParent(); if (!parent) { return nullptr; diff --git a/dom/html/HTMLOptionElement.h b/dom/html/HTMLOptionElement.h @@ -109,18 +109,17 @@ class HTMLOptionElement final : public nsGenericHTMLElement { void SetText(const nsAString& aText, ErrorResult& aRv); int32_t Index(); - - protected: - virtual ~HTMLOptionElement(); - - JSObject* WrapNode(JSContext*, JS::Handle<JSObject*> aGivenProto) override; - /** * Get the select content element that contains this option, this * intentionally does not return nsresult, all we care about is if * there's a select associated with this option or not. */ - HTMLSelectElement* GetSelect(); + HTMLSelectElement* GetSelect() const; + + protected: + virtual ~HTMLOptionElement(); + + JSObject* WrapNode(JSContext*, JS::Handle<JSObject*> aGivenProto) override; bool mSelectedChanged = false; diff --git a/toolkit/components/find/nsFind.cpp b/toolkit/components/find/nsFind.cpp @@ -205,7 +205,7 @@ static bool SkipNode(const nsIContent* aContent) { // Skip option nodes if their select is a combo box, or if they // have no select (somehow). if (const auto* option = HTMLOptionElement::FromNode(content)) { - auto* select = HTMLSelectElement::FromNodeOrNull(option->GetParent()); + const auto* select = option->GetSelect(); if (!select || select->IsCombobox()) { DEBUG_FIND_PRINTF("Skipping node: "); DumpNode(content); diff --git a/toolkit/components/find/test/mochitest/test_nsFind.html b/toolkit/components/find/test/mochitest/test_nsFind.html @@ -345,6 +345,12 @@ async function runTests() { assertNotFound(space, "\u{3000D}"); assertNotFound(space, "\u{3000A}"); + // Bug 1951607: Text inside <option> elements within <optgroup> in a <select> + // should be findable. + var selectElement = document.getElementById("select-with-optgroup"); + assertFound(selectElement, "optgroup"); + assertFound(selectElement, "OptionInOptGroup"); + // Do these test at the end since they trigger failure screenshots in // the test harness, and we want as much information as possible about // any OTHER tests that may have already failed. @@ -456,6 +462,11 @@ async function runTests() { </div> <p id="nonspace">&#x2000D;&#x10000A;</p> <p id="space"> <br>&nbsp;</p> +<select id="select-with-optgroup" multiple> + <optgroup label="optgroup"> + <option>OptionInOptGroup</option> + </optgroup> +</select> <pre id="test"> </pre> </body>