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

Regexp: \r and \n not handled properly

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Not an Issue
    • Affects Version/s: 8u111
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
      None

      Description

      Hi

      I stumbled upon a minor discrepancy between Nashorn and other
      JavaScript engines when doing regexp matching with the multiline flag
      enabled.

      Nashorn
      ```
      $ jjs -version
      nashorn 1.8.0_111
      jjs> String.prototype.replace.apply("a\nb\rc\n\rd\r\ne", [/^(.*)/gm,"*$1"]);
      *a
      *c
      **
      *e
      ```

      Notice that the characters 'b' and 'd' are gone from the output.

      Node:
      ```
      $ node --version
      v5.5.0
      $ node
      String.prototype.replace.apply("a\nb\rc\n\rd\r\ne", [/^(.*)/gm,"*$1"]);
      '*a\n*b\r*c\n*\r*d\r*\n*e'
      ```

      Firefox & Chrome console:
      ```
      String.prototype.replace.apply("a\nb\rc\n\rd\r\ne", [/^(.*)/gm,"*$1"]);
      "*a
      *b
      *c
      *
      *d
      *
      *e"
      ```

      Notice that the characters 'b' and 'd' are in the output.

      -

      I suspect the cause is that nashorn does treat the character after
      '\r' as being at the start of a line.

      -
      Esben

        Attachments

          Activity

            People

            • Assignee:
              hannesw Hannes Wallnoefer
              Reporter:
              jlaskey Jim Laskey
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: