From 3340d98167318bba0c2421688b3e5066e33797f3 Mon Sep 17 00:00:00 2001 From: Edward Jensen Date: Mon, 25 Apr 2022 12:46:05 -0500 Subject: [PATCH] Fix ClassCastException when using StringBuilder/Buffer #496 --- .../javascript/tests/Issue1206Test.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 testsrc/org/mozilla/javascript/tests/Issue1206Test.java diff --git a/testsrc/org/mozilla/javascript/tests/Issue1206Test.java b/testsrc/org/mozilla/javascript/tests/Issue1206Test.java new file mode 100644 index 0000000000..a64cd9e0d9 --- /dev/null +++ b/testsrc/org/mozilla/javascript/tests/Issue1206Test.java @@ -0,0 +1,36 @@ +/* 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/. */ + +package org.mozilla.javascript.tests; + +import org.junit.Test; +import org.mozilla.javascript.Context; +import org.mozilla.javascript.Scriptable; + +/** Tests the ConsString class to ensure it properly supports String, StringBuffer and StringBuilder. */ +public class Issue1206Test { + @Test + public void testConsStringUsingString() { + Context cx = Context.enter(); + Scriptable scope = cx.initStandardObjects(null); + scope.put("var1", scope, "hello"); + cx.evaluateString(scope, "var1 = var1 + ' world'", "test", 1, null); + } + + @Test + public void testConsStringUsingStringBuffer() { + Context cx = Context.enter(); + Scriptable scope = cx.initStandardObjects(null); + scope.put("var1", scope, new StringBuffer("hello")); + cx.evaluateString(scope, "var1 = var1 + ' world'", "test", 1, null); + } + + @Test + public void testConsStringUsingStringBuilder() { + Context cx = Context.enter(); + Scriptable scope = cx.initStandardObjects(null); + scope.put("var1", scope, new StringBuilder("hello")); + cx.evaluateString(scope, "var1 = var1 + ' world'", "test", 1, null); + } +}