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

An Exception should be thrown when initialize RegExp with parameter "{"

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 8, 11, 12.0.1, 13, 14
    • Fix Version/s: None
    • Component/s: core-libs

      Description

      ADDITIONAL SYSTEM INFORMATION :
      When running the following testcase with 'jjs', the output is 'AB'.
      var string = "A{";
      var reg = new RegExp("{");
      print(string.replace(reg, "B"));

      A DESCRIPTION OF THE PROBLEM :
      For '{' is a special character, it should be used together with '}' or used as '\\{' to match '{' in a string. Therefore constructor of RegExp should throw an exception when doing 'new RegExp("{").'

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a test file as 't.js' with the following content
      var string = "A{";
      var reg = new RegExp("{");
      print(string.replace(reg, "B"));
      2. run './jjs ./t.js' in '%JDK12.0.1_HOME%/bin'

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      SyntaxError
      ACTUAL -
      console output 'AB'

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              hannesw Hannes Wallnoefer
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: