Fix multiple issues when expanding argfiles
- treat a contiguous whitespace sequence as a single argument separator, not as several empty-string arguments separated by whitespaces - fix infinite loop when reading unfinished quoted argument - do not attempt to perform escape if the backslash is the last character in the file
This commit is contained in:
committed by
Dmitry Savvinov
parent
61902e1fd5
commit
06d97cce51
+18
-11
@@ -48,29 +48,36 @@ private fun File.expand(errors: ArgumentParseErrors): List<String> {
|
|||||||
private fun Reader.parseNextArgument(): String? {
|
private fun Reader.parseNextArgument(): String? {
|
||||||
val sb = StringBuilder()
|
val sb = StringBuilder()
|
||||||
|
|
||||||
var r: Int = read()
|
var r = nextChar()
|
||||||
while (r != -1) {
|
while (r != null && (r == WHITESPACE || r == NEWLINE)) {
|
||||||
when (r.toChar()) {
|
r = nextChar()
|
||||||
WHITESPACE, NEWLINE -> return sb.toString()
|
}
|
||||||
|
|
||||||
|
loop@ while (r != null) {
|
||||||
|
when (r) {
|
||||||
|
WHITESPACE, NEWLINE -> break@loop
|
||||||
QUOTATION_MARK -> consumeRestOfEscapedSequence(sb)
|
QUOTATION_MARK -> consumeRestOfEscapedSequence(sb)
|
||||||
BACKSLASH -> sb.append(read().toChar())
|
BACKSLASH -> nextChar()?.apply(sb::append)
|
||||||
else -> sb.append(r.toChar())
|
else -> sb.append(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
r = read()
|
r = nextChar()
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.toString().takeIf { it.isNotEmpty() }
|
return sb.toString().takeIf { it.isNotEmpty() }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Reader.consumeRestOfEscapedSequence(sb: StringBuilder) {
|
private fun Reader.consumeRestOfEscapedSequence(sb: StringBuilder) {
|
||||||
var ch = read().toChar()
|
var ch = nextChar()
|
||||||
while (ch != QUOTATION_MARK) {
|
while (ch != null && ch != QUOTATION_MARK) {
|
||||||
if (ch == BACKSLASH) sb.append(read().toChar()) else sb.append(ch)
|
if (ch == BACKSLASH) nextChar()?.apply(sb::append) else sb.append(ch)
|
||||||
ch = read().toChar()
|
ch = nextChar()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Reader.nextChar(): Char? =
|
||||||
|
read().takeUnless { it == -1 }?.toChar()
|
||||||
|
|
||||||
private val String.argfilePath: String
|
private val String.argfilePath: String
|
||||||
get() = removePrefix("$EXPERIMENTAL_ARGFILE_ARGUMENT=")
|
get() = removePrefix("$EXPERIMENTAL_ARGFILE_ARGUMENT=")
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
$TESTDATA_DIR$/simple.kt -d $TEMP_DIR$
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-jdk-home "abacaba\
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
-Xargfile=$TESTDATA_DIR$/argfileWithUnfinishedQuoteAndEscape.argfile
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
error: JDK home directory does not exist: abacaba
|
||||||
|
|
||||||
|
COMPILATION_ERROR
|
||||||
@@ -71,6 +71,11 @@ public class CliTestGenerated extends AbstractCliTest {
|
|||||||
runTest("compiler/testData/cli/jvm/argfileWithEscaping.args");
|
runTest("compiler/testData/cli/jvm/argfileWithEscaping.args");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("argfileWithUnfinishedQuoteAndEscape.args")
|
||||||
|
public void testArgfileWithUnfinishedQuoteAndEscape() throws Exception {
|
||||||
|
runTest("compiler/testData/cli/jvm/argfileWithUnfinishedQuoteAndEscape.args");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("argumentPassedMultipleTimes.args")
|
@TestMetadata("argumentPassedMultipleTimes.args")
|
||||||
public void testArgumentPassedMultipleTimes() throws Exception {
|
public void testArgumentPassedMultipleTimes() throws Exception {
|
||||||
runTest("compiler/testData/cli/jvm/argumentPassedMultipleTimes.args");
|
runTest("compiler/testData/cli/jvm/argumentPassedMultipleTimes.args");
|
||||||
|
|||||||
Reference in New Issue
Block a user