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

Nashorn engine exec("ba") returns null but other engines return ["ba", "a"]

    XMLWordPrintable

Details

    Description

      A DESCRIPTION OF THE PROBLEM :
      The code below does not have the same behavior as other engines (e.g., V8 in Google Chrome,SpiderMonkey in Firefox,graaljs,hermes,V8 in nodejs,JaegerMonkey in Firefox,JerryScript,mulversion in Firefox,chakra in Edge,carakan in Opera,quickjs,nitro in Safari).

      var regex=/(((a)\2))/
      console.log(regex.exec("aaa"))

      In JavaScriptCore, the output is
      null
      However, in V8,SpiderMonkey,chakra ,graaljs,hermes,JaegerMonkey,JerryScript,mulversion,carakan,quickjs and nitro,output is
      ['a', 'a', 'a', 'a', index: 0, input: 'aaa', groups: undefined]

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Write and run the following code under jdk1.6:
      import javax.script.ScriptEngineManager;
      import javax.script.ScriptEngine;
      import javax.script.ScriptException;
      import javax.script.SimpleBindings;
      import javax.script.*;
      import java.io.*;
      import java.util.*;
      import java.util.ArrayList;
      import java.util.List;
      import java.util.concurrent.*;
      import java.util.logging.Logger;
      import java.util.regex.*;

      public class test {
           public static void main(String[] args) throws FileNotFoundException, ScriptException, NoSuchMethodException {
               ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
               ScriptEngine nashorn = scriptEngineManager.getEngineByName("nashorn");
               String script = "function test() {var regex = /(((a)\\2))/\n" +
                       "print(regex.exec(\"aaa\"))}";
               nashorn.eval(script);
               Invocable inv = (Invocable) nashorn;
               inv.invokeFunction("test");

           }
      }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      ['a', 'a', 'a', 'a', index: 0, input: 'aaa', groups: undefined]

      ---------- BEGIN SOURCE ----------
      String script = "function test() {var regex = /(((a)\\2))/\n" +
                       "print(regex.exec(\"aaa\"))}";
               nashorn.eval(script);
               Invocable inv = (Invocable) nashorn;
               inv.invokeFunction("test");
      ---------- END SOURCE ----------

      FREQUENCY : always


      Attachments

        Activity

          People

            attila Attila Szegedi
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: