Skip to content

Commit

Permalink
Make sure we ignore whitespace in java options
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Mar 24, 2020
1 parent 0aaa141 commit 3383b7f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ describe("getJavaOptions", () => {
expect(options).toEqual(proxyOptions);
});

it("sanitizes options from .jvmopts", () => {
const malformedOptions = ["-XX:+UseNUMA ", "-XX:+UseZGC "];
const expectedOptions = ["-XX:+UseNUMA", "-XX:+UseZGC"];
const workspaceRoot = createWorskpace(malformedOptions);
const options = getJavaOptions(workspaceRoot);
expect(options).toEqual(expectedOptions);
});

it("reads from JAVA_OPTS", () => {
process.env = { ...originalEnv, JAVA_OPTS: proxyOptions.join(" ") };
const workspaceRoot = createWorskpace([]);
Expand Down
6 changes: 5 additions & 1 deletion packages/metals-languageclient/src/getJavaOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import { parse } from "shell-quote";
*/
export function getJavaOptions(workspaceRoot: string | undefined): string[] {
const allOptions = [...fromEnv(), ...fromJvmoptsFile(workspaceRoot)];
return allOptions.filter(isValidOption);
return allOptions.filter(isValidOption).map(sanitizeOption);
}

function sanitizeOption(option: string): string {
return option.trim();
}

function isValidOption(option: string): boolean {
Expand Down

0 comments on commit 3383b7f

Please sign in to comment.