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

Greedy matching against supplementary chars fails to respect the region

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 15
    • 7, 8, 11, 14, 15
    • core-libs
    • 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

            igerasim Ivan Gerasimov
            igerasim Ivan Gerasimov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: