Skip to content
Permalink
Browse files
8246042: Non-ASCII characters are not handled correctly in the native…
… launcher

Reviewed-by: herrick, almatvee
  • Loading branch information
Alexey Semenyuk committed Jun 11, 2020
1 parent 6098191 commit a2401333fad1594392991fc482ddbcb903331ec7
Showing 6 changed files with 96 additions and 2 deletions.
@@ -169,7 +169,19 @@ void Jvm::launch() {
jint ergo);

std::vector<char*> argv;
#ifdef TSTRINGS_WITH_WCHAR
std::vector<std::string> mbcs_args;
do {
tstring_array::const_iterator it = args.begin();
const tstring_array::const_iterator end = args.end();
for (; it != end; ++it) {
mbcs_args.push_back(tstrings::toACP(*it));
}
} while (0);
convertArgs(mbcs_args, argv);
#else
convertArgs(args, argv);
#endif

// Don't count terminal '0'.
const int argc = (int)argv.size() - 1;
@@ -37,7 +37,7 @@ class Jvm {
Jvm& initFromConfigFile(const CfgFile& cfgFile);

Jvm& addArgument(const tstring& value) {
args.push_back(tstrings::any(value).str());
args.push_back(value);
return *this;
}

@@ -54,7 +54,7 @@ class Jvm {

private:
tstring jvmPath;
std::vector<std::string> args;
tstring_array args;
};

#endif // JvmLauncher_h
@@ -275,6 +275,10 @@ std::wstring fromMultiByte(const std::string& str, int encoding) {
}
} // namespace

std::string toACP(const std::wstring& utf16str) {
return toMultiByte(utf16str, CP_ACP);
}

std::string toUtf8(const std::wstring& utf16str) {
return toMultiByte(utf16str, CP_UTF8);
}
@@ -140,6 +140,9 @@ namespace tstrings {
}

#ifdef TSTRINGS_WITH_WCHAR
// conversion to the active code page
std::string toACP(const std::wstring& utf16str);

// conversion to Utf8
std::string toUtf8(const std::wstring& utf16str);

@@ -50,6 +50,11 @@ public static void main(String[] args) throws IOException, InterruptedException

var lines = printArgs(args);

Stream.of(args).forEach(arg -> System.out.println(
arg.codePoints()
.mapToObj(codePoint -> String.format("0x%04x", codePoint))
.collect(Collectors.joining(",", "[", "]"))));

lines.forEach(System.out::println);

var outputFile = getOutputFile(args);
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package jdk.jpackage.tests;

import java.util.stream.Collectors;
import jdk.jpackage.test.TKit;
import jdk.jpackage.test.Annotations.Test;
import jdk.jpackage.test.Annotations.Parameter;
import jdk.jpackage.test.HelloApp;
import jdk.jpackage.test.JPackageCommand;

/*
* @test
* @summary test how app launcher handles unicode command line arguments
* @library ../../../../helpers
* @build jdk.jpackage.test.*
* @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal
* @compile UnicodeArgsTest.java
* @requires (os.family == "windows")
* @run main/othervm/timeout=720 -Xmx512m jdk.jpackage.test.Main
* --jpt-run=jdk.jpackage.tests.UnicodeArgsTest
*/

public final class UnicodeArgsTest {

@Parameter("true")
@Parameter("false")
@Test
public void test8246042(boolean onCommandLine) {
final String testString = new String(Character.toChars(0x00E9));

TKit.trace(String.format("Test string code points: %s", testString
.codePoints()
.mapToObj(codePoint -> String.format("0x%04x", codePoint))
.collect(Collectors.joining(",", "[", "]"))));

JPackageCommand cmd = JPackageCommand.helloAppImage().useToolProvider(true);
if (!onCommandLine) {
cmd.addArguments("--arguments", testString);
}
cmd.executeAndAssertImageCreated();

if (onCommandLine) {
HelloApp.executeLauncherAndVerifyOutput(cmd, testString);
} else {
HelloApp.executeLauncherAndVerifyOutput(cmd);
}
}
}

0 comments on commit a240133

Please sign in to comment.