Skip to content

Commit

Permalink
Fix parsing of editor commandline in git-pr
Browse files Browse the repository at this point in the history
Reviewed-by: rwestberg
  • Loading branch information
RealCLanger authored and rwestberg committed Feb 12, 2020
1 parent 4248ba2 commit 9b9160b
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions cli/src/main/java/org/openjdk/skara/cli/GitPr.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 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
Expand Down Expand Up @@ -40,12 +40,11 @@
import java.util.*;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.stream.Collectors;

public class GitPr {
private static final StandardOpenOption APPEND = StandardOpenOption.APPEND;
private static final Pattern ISSUE_ID_PATTERN = Pattern.compile("([A-Za-z][A-Za-z0-9]+)?-([0-9]+)");
private static final Pattern ISSUE_MARKDOWN_PATTERN =
Pattern.compile("^\\[([A-Z]+-[0-9]+)\\]\\(https:\\/\\/bugs.openjdk.java.net\\/browse\\/[A-Z]+-[0-9]+\\): .*$");
Expand All @@ -55,13 +54,6 @@ private static void exit(String fmt, Object...args) {
System.exit(1);
}

private static <T> Supplier<T> die(String fmt, Object... args) {
return () -> {
exit(fmt, args);
return null;
};
}

private static String gitConfig(String key) {
try {
var pb = new ProcessBuilder("git", "config", key);
Expand Down Expand Up @@ -304,7 +296,17 @@ private static boolean spawnEditor(ReadOnlyRepository repo, Path file) throws IO
editor = "vi";
}

var pb = new ProcessBuilder(editor, file.toString());
// As an editor command may have multiple arguments, we need to add each single one
// to the ProcessBuilder. Arguments are split by whitespace and can be quoted.
// e.g. I found core.editor =
// \"C:\\\\Program Files\\\\Notepad++\\\\notepad++.exe\" -multiInst -notabbar -nosession -noPlugin
List<String> editorParts = new ArrayList<>();
Matcher em = Pattern.compile("\\s*([^\"]\\S*|\".+?\")\\s*").matcher(editor);
while (em.find()) {
editorParts.add(em.group(1));
}
editorParts.add(file.toString());
var pb = new ProcessBuilder(editorParts);
pb.inheritIO();
var p = pb.start();
try {
Expand Down

0 comments on commit 9b9160b

Please sign in to comment.