Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8237599

Greedy matching against supplementary chars fails to respect the region

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 7, 8, 11, 14, 15
    • Fix Version/s: 15
    • Component/s: core-libs
    • Labels:
      None

      Description

      The following code demonstrates the bug:

      import java.util.regex.*;
      public class T {
          public static void main(String[] args) throws Throwable {
              String input = "\ud801\udc37";
              Pattern p = Pattern.compile(".+");
              Matcher m = p.matcher(input);
              m.region(0, 1);
              if (m.find()) {
                  System.out.println(": " + m.group(0) + " : " + m.group(0).length());
              }
          }
      }

      It is expected to print a single high half of the surrogate pair, and its length of 1.
      In reality, it prints
      : 𐐷 : 2
      i.e. the result crosses the boundary of a set region.

        Attachments

          Activity

            People

            • Assignee:
              igerasim Ivan Gerasimov (Inactive)
              Reporter:
              igerasim Ivan Gerasimov (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: