<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - RegExp /y flag incorrect handling of mixed-length alternation"
   href="https://bugs.webkit.org/show_bug.cgi?id=157723">157723</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>RegExp /y flag incorrect handling of mixed-length alternation
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>WebKit
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>Safari Technology Preview
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Unspecified
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>OS X 10.11
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>Normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P2
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>JavaScriptCore
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>webkit-unassigned&#64;lists.webkit.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>steves_list&#64;hotmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This issue broke the XRegExp library. I've added a workaround in XRegExp 3.1.1 -- see &lt;<a href="https://github.com/slevithan/xregexp/issues/135">https://github.com/slevithan/xregexp/issues/135</a>&gt;.

Safari Technology Preview v9.1.1 has a bug in its handling of the ES 2015 RegExp /y flag. Here is some test output, with the last example showing the bug:

```
/a|b/y.test('a'); // -&gt; true
/a|b/y.test('b'); // -&gt; true
/b|a/y.test('a'); // -&gt; true
/b|a/y.test('b'); // -&gt; true
/aa|bb/y.test('aa'); // -&gt; true
/aa|bb/y.test('bb'); // -&gt; true
/bb|aa/y.test('aa'); // -&gt; true
/bb|aa/y.test('bb'); // -&gt; true
/a|bb/y.test('a'); // -&gt; true
/a|bb/y.test('bb'); // -&gt; true
/bb|a/y.test('bb'); // -&gt; true
/bb|a/y.test('a'); // -&gt; false [should be true]
```

It seems that if a regex with flag y evaluates a path within a regex with more than 1 character, it advances its internal lastIndex that the y flag is anchored to, and does not reset this position when the alternative fails and another path in the regex with fewer characters to match is tried. Or something along those lines.

Safari 9.1 does not have this issue, since 9.1.1 is the first version to support /y. Also, no other current browser that supports /y (Edge, Firefox, Chrome, Opera) has this bug.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>