<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>25868</bug_id>
          
          <creation_ts>2009-05-19 10:39:00 -0700</creation_ts>
          <short_desc>Frame::markAllMatchesForText prematurely aborts while highlighting text</short_desc>
          <delta_ts>2023-06-02 19:26:43 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>New Bugs</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>UNCONFIRMED</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>0</everconfirmed>
          <reporter name="Finnur Thorarinsson">finnur.webkit</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>mitz</cc>
    
    <cc>rniwa</cc>
    
    <cc>simon.fraser</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>121936</commentid>
    <comment_count>0</comment_count>
    <who name="Finnur Thorarinsson">finnur.webkit</who>
    <bug_when>2009-05-19 10:39:00 -0700</bug_when>
    <thetext>I can easily reproduce a problem with highlighting in Frame::markAllMatchesForText. 

The problem is this:

On certain HTML files, the markAllMatchesForText is aborted before reaching the end (resulting in failure to highlight matches). 

A superficial look through the annotations lead me to a bug titled &quot;Searching in text areas&quot; (https://bugs.webkit.org/show_bug.cgi?id=7023), which was fixed and I think causes this.

I have a reduced HTML code that I use to reproduce this bug:

&lt;!doctype html&gt;
&lt;body&gt;
  &lt;input type=text value=&quot;html&quot;&gt; 
  Call markAllMatchesForText with html[space] and it should highlight these words: html html done.
&lt;/body&gt;

Note that &lt;input type=text&gt; has the string &quot;html&quot; in it.

If you call markAllMatchesForText for &quot;html &quot; (note the trailing space) on this frame, it will break and not highlight anything (see comment). Observe my comment in the snippet below, which is where it breaks.

unsigned Frame::markAllMatchesForText(const String&amp; target, bool caseFlag, unsigned limit)
{
    if (target.isEmpty())
        return 0;
    
    RefPtr&lt;Range&gt; searchRange(rangeOfContents(document()));
    
    ExceptionCode exception = 0;
    unsigned matchCount = 0;
    do {
        RefPtr&lt;Range&gt; resultRange(findPlainText(searchRange.get(), target, true, caseFlag));
        if (resultRange-&gt;collapsed(exception)) {
            if (!resultRange-&gt;startContainer()-&gt;isInShadowTree())
                break;  //  &lt;&lt;  NOTE: THIS IS WHERE IT ABORTS.


If it is easy to fix, feel free to suggest changes to this code that will make this work and I would be happy to try it out in my tree and submit a patch (if it works).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1959658</commentid>
    <comment_count>1</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2023-06-02 19:26:43 -0700</bug_when>
    <thetext>This looks totally different code now:

https://searchfox.org/wubkat/source/Source/WebCore/page/Page.cpp#983


unsigned Page::markAllMatchesForText(const String&amp; target, FindOptions options, bool shouldHighlight, unsigned maxMatchCount)
{
    return findMatchesForText(target, options, maxMatchCount, shouldHighlight ? HighlightMatches : DoNotHighlightMatches, MarkMatches);
}

Anything to do here?</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>