Skip to content

Commit

Permalink
fix issue #648
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri authored and gbrail committed May 27, 2020
1 parent 632bb4c commit ef02aa3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/org/mozilla/javascript/regexp/RegExpImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public Object action(Context cx, Scriptable scope,
int index = str.indexOf(search);
if (index >= 0) {
int slen = search.length();
this.parens = null;
this.lastParen = null;
this.leftContext = new SubString(str, 0, index);
this.lastMatch = new SubString(str, index, slen);
Expand Down Expand Up @@ -756,8 +757,7 @@ private static int find_split(Context cx, Scriptable scope, String target,

protected String input; /* input string to match (perl $_, GC root) */
protected boolean multiline; /* whether input contains newlines (perl $*) */
protected SubString[] parens; /* Vector of SubString; last set of parens
matched (perl $1, $2) */
protected SubString[] parens; /* Vector of SubString; last set of parens matched (perl $1, $2) */
protected SubString lastMatch; /* last string matched (perl $&) */
protected SubString lastParen; /* last paren matched (perl $+) */
protected SubString leftContext; /* input to left of last match (perl $`) */
Expand Down
49 changes: 49 additions & 0 deletions testsrc/org/mozilla/javascript/tests/es5/RegexpTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/*
* Tests for the Object.getOwnPropertyDescriptor(obj, prop) method
*/
package org.mozilla.javascript.tests.es5;
import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ScriptableObject;

public class RegexpTest {

private Context cx;
private ScriptableObject scope;

@Before
public void setUp() {
cx = Context.enter();
cx.setLanguageVersion(Context.VERSION_1_8);
scope = cx.initStandardObjects();
}

@After
public void tearDown() {
Context.exit();
}

/**
* see https://github.com/mozilla/rhino/issues/684.
*/
@Test
public void testSideEffect() {
Object result2 = cx.evaluateString(
scope, "var a = 'hello world';"
+ "a.replace(/(.)/g, '#');"
+ "var res = '';"
+ "a.replace([], function (b, c) { res += c; });"
+ "res;",
"test", 1, null
);
assertEquals("0", result2);
}
}

0 comments on commit ef02aa3

Please sign in to comment.