Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ internal static bool TryReadResponseFile(string rspFilePath, ICollection<string>
{
errors.Add(string.Format(CultureInfo.InvariantCulture, PlatformResources.CommandLineParserFailedToReadResponseFile, rspFilePath, e.ToString()));
}
catch (UnauthorizedAccessException e)
{
errors.Add(string.Format(CultureInfo.InvariantCulture, PlatformResources.CommandLineParserFailedToReadResponseFile, rspFilePath, e.Message));
}
catch (FormatException e)
{
Comment thread
Evangelink marked this conversation as resolved.
errors.Add(string.Format(CultureInfo.InvariantCulture, PlatformResources.CommandLineParserFailedToReadResponseFile, rspFilePath, e.Message));
}
Comment on lines +26 to +33
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds unrelated to what the PR wants to do.


newArguments = null;
return false;
Expand All @@ -36,14 +44,14 @@ static IEnumerable<string> ExpandResponseFile(string filePath)
{
string line = lines[i];

foreach (string p in SplitLine(line))
foreach (string p in SplitLine(line, i + 1))
{
yield return p;
}
}
}

static IEnumerable<string> SplitLine(string line)
static IEnumerable<string> SplitLine(string line, int lineNumber)
{
string arg = line.Trim();

Expand All @@ -52,7 +60,7 @@ static IEnumerable<string> SplitLine(string line)
yield break;
}

foreach (string word in SplitCommandLine(arg))
foreach (string word in SplitCommandLine(arg, lineNumber))
{
yield return word;
}
Expand All @@ -68,6 +76,9 @@ private enum Boundary
}

public static IEnumerable<string> SplitCommandLine(string commandLine)
=> SplitCommandLine(commandLine, lineNumber: null);

private static IEnumerable<string> SplitCommandLine(string commandLine, int? lineNumber)
{
int startTokenIndex = 0;

Expand Down Expand Up @@ -140,6 +151,13 @@ public static IEnumerable<string> SplitCommandLine(string commandLine)

if (IsAtEndOfInput())
{
if (seekingQuote == Boundary.QuoteEnd)
{
throw new FormatException(lineNumber is null
? PlatformResources.CommandLineParserUnclosedQuoteInCommandLine
: string.Format(CultureInfo.InvariantCulture, PlatformResources.CommandLineParserUnclosedQuoteInResponseFile, lineNumber));
}

switch (seeking)
{
case Boundary.TokenStart:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,13 @@ Takes one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is
<value>Failed to read response file '{0}'. {1}.</value>
<comment>{1} is the exception</comment>
</data>
<data name="CommandLineParserUnclosedQuoteInResponseFile" xml:space="preserve">
<value>Unclosed quote in response file at line {0}</value>
<comment>{0} is the line number</comment>
</data>
<data name="CommandLineParserUnclosedQuoteInCommandLine" xml:space="preserve">
<value>Unclosed quote in command line</value>
</data>
<data name="PlatformCommandLineMinimumExpectedTestsOptionDescription" xml:space="preserve">
<value>Specifies the minimum number of tests that are expected to run.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@
<target state="translated">Soubor odpovědí {0} nebyl nalezen.</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInCommandLine">
<source>Unclosed quote in command line</source>
<target state="new">Unclosed quote in command line</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInResponseFile">
<source>Unclosed quote in response file at line {0}</source>
<target state="new">Unclosed quote in response file at line {0}</target>
<note>{0} is the line number</note>
</trans-unit>
<trans-unit id="CommandLineParserUnexpectedArgument">
<source>Unexpected argument {0}</source>
<target state="translated">Neočekávaný argument {0}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@
<target state="translated">Die Antwortdatei "{0}" wurde nicht gefunden.</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInCommandLine">
<source>Unclosed quote in command line</source>
<target state="new">Unclosed quote in command line</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInResponseFile">
<source>Unclosed quote in response file at line {0}</source>
<target state="new">Unclosed quote in response file at line {0}</target>
<note>{0} is the line number</note>
</trans-unit>
<trans-unit id="CommandLineParserUnexpectedArgument">
<source>Unexpected argument {0}</source>
<target state="translated">Unerwartetes Argument {0}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@
<target state="translated">No se encontró el archivo de respuesta "{0}"</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInCommandLine">
<source>Unclosed quote in command line</source>
<target state="new">Unclosed quote in command line</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInResponseFile">
<source>Unclosed quote in response file at line {0}</source>
<target state="new">Unclosed quote in response file at line {0}</target>
<note>{0} is the line number</note>
</trans-unit>
<trans-unit id="CommandLineParserUnexpectedArgument">
<source>Unexpected argument {0}</source>
<target state="translated">Argumento inesperado {0}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@
<target state="translated">Le fichier réponse « {0} » est introuvable</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInCommandLine">
<source>Unclosed quote in command line</source>
<target state="new">Unclosed quote in command line</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInResponseFile">
<source>Unclosed quote in response file at line {0}</source>
<target state="new">Unclosed quote in response file at line {0}</target>
<note>{0} is the line number</note>
</trans-unit>
<trans-unit id="CommandLineParserUnexpectedArgument">
<source>Unexpected argument {0}</source>
<target state="translated">Arguments inattendue {0}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@
<target state="translated">Il file di risposta “{0}” non è stato trovato</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInCommandLine">
<source>Unclosed quote in command line</source>
<target state="new">Unclosed quote in command line</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInResponseFile">
<source>Unclosed quote in response file at line {0}</source>
<target state="new">Unclosed quote in response file at line {0}</target>
<note>{0} is the line number</note>
</trans-unit>
<trans-unit id="CommandLineParserUnexpectedArgument">
<source>Unexpected argument {0}</source>
<target state="translated">Argomento imprevisto {0}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@
<target state="translated">応答ファイル '{0}' が見つかりませんでした</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInCommandLine">
<source>Unclosed quote in command line</source>
<target state="new">Unclosed quote in command line</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInResponseFile">
<source>Unclosed quote in response file at line {0}</source>
<target state="new">Unclosed quote in response file at line {0}</target>
<note>{0} is the line number</note>
</trans-unit>
<trans-unit id="CommandLineParserUnexpectedArgument">
<source>Unexpected argument {0}</source>
<target state="translated">予期しない引数 {0}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@
<target state="translated">응답 파일 '{0}'을(를) 찾을 수 없습니다.</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInCommandLine">
<source>Unclosed quote in command line</source>
<target state="new">Unclosed quote in command line</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInResponseFile">
<source>Unclosed quote in response file at line {0}</source>
<target state="new">Unclosed quote in response file at line {0}</target>
<note>{0} is the line number</note>
</trans-unit>
<trans-unit id="CommandLineParserUnexpectedArgument">
<source>Unexpected argument {0}</source>
<target state="translated">예기치 않은 인수 {0}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@
<target state="translated">Nie znaleziono pliku odpowiedzi „{0}”</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInCommandLine">
<source>Unclosed quote in command line</source>
<target state="new">Unclosed quote in command line</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInResponseFile">
<source>Unclosed quote in response file at line {0}</source>
<target state="new">Unclosed quote in response file at line {0}</target>
<note>{0} is the line number</note>
</trans-unit>
<trans-unit id="CommandLineParserUnexpectedArgument">
<source>Unexpected argument {0}</source>
<target state="translated">Nieoczekiwany argument {0}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@
<target state="translated">O arquivo de resposta '{0}' não foi encontrado</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInCommandLine">
<source>Unclosed quote in command line</source>
<target state="new">Unclosed quote in command line</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInResponseFile">
<source>Unclosed quote in response file at line {0}</source>
<target state="new">Unclosed quote in response file at line {0}</target>
<note>{0} is the line number</note>
</trans-unit>
<trans-unit id="CommandLineParserUnexpectedArgument">
<source>Unexpected argument {0}</source>
<target state="translated">Argumento inesperado {0}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@
<target state="translated">Файл ответа "{0}" не найден</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInCommandLine">
<source>Unclosed quote in command line</source>
<target state="new">Unclosed quote in command line</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInResponseFile">
<source>Unclosed quote in response file at line {0}</source>
<target state="new">Unclosed quote in response file at line {0}</target>
<note>{0} is the line number</note>
</trans-unit>
<trans-unit id="CommandLineParserUnexpectedArgument">
<source>Unexpected argument {0}</source>
<target state="translated">Неожиданный аргумент {0}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@
<target state="translated">'{0}' yanıt dosyası bulunamadı</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInCommandLine">
<source>Unclosed quote in command line</source>
<target state="new">Unclosed quote in command line</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInResponseFile">
<source>Unclosed quote in response file at line {0}</source>
<target state="new">Unclosed quote in response file at line {0}</target>
<note>{0} is the line number</note>
</trans-unit>
<trans-unit id="CommandLineParserUnexpectedArgument">
<source>Unexpected argument {0}</source>
<target state="translated">{0} bağımsız değişkeni beklenmiyordu</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@
<target state="translated">找不到响应文件“{0}”</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInCommandLine">
<source>Unclosed quote in command line</source>
<target state="new">Unclosed quote in command line</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInResponseFile">
<source>Unclosed quote in response file at line {0}</source>
<target state="new">Unclosed quote in response file at line {0}</target>
<note>{0} is the line number</note>
</trans-unit>
<trans-unit id="CommandLineParserUnexpectedArgument">
<source>Unexpected argument {0}</source>
<target state="translated">意外的参数 {0}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@
<target state="translated">找不到回應檔案 '{0}'</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInCommandLine">
<source>Unclosed quote in command line</source>
<target state="new">Unclosed quote in command line</target>
<note />
</trans-unit>
<trans-unit id="CommandLineParserUnclosedQuoteInResponseFile">
<source>Unclosed quote in response file at line {0}</source>
<target state="new">Unclosed quote in response file at line {0}</target>
<note>{0} is the line number</note>
</trans-unit>
<trans-unit id="CommandLineParserUnexpectedArgument">
<source>Unexpected argument {0}</source>
<target state="translated">未預期的引數 {0}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,30 @@ public void TryReadResponseFile_FileWithQuotedArguments_QuotesAreStripped()
}
}

[TestMethod]
public void TryReadResponseFile_FileWithUnclosedQuote_ReturnsFalseAndAddsError()
{
string path = Path.GetTempFileName();
try
{
File.WriteAllLines(path, ["--verbose", "--filter \"FullyQualifiedName~My.Namespace"]);
var errors = new List<string>();

bool result = ResponseFileHelper.TryReadResponseFile(path, errors, out string[]? args);

Assert.IsFalse(result);
Assert.IsNull(args);
Assert.HasCount(1, errors);
Assert.Contains(path, errors[0]);
Assert.Contains("line 2", errors[0]);
Assert.Contains("Unclosed quote", errors[0]);
}
finally
{
File.Delete(path);
}
}

[TestMethod]
public void TryReadResponseFile_EmptyFile_ReturnsTrueWithEmptyArray()
{
Expand Down Expand Up @@ -294,12 +318,8 @@ public void SplitCommandLine_QuotedStringContainingMultipleSpaces_PreservesInter
}

[TestMethod]
public void SplitCommandLine_UnclosedQuote_ReturnsEmpty()
{
string[] result = [.. ResponseFileHelper.SplitCommandLine("\"hello world")];

Assert.IsEmpty(result);
}
public void SplitCommandLine_UnclosedQuote_ThrowsFormatException()
=> Assert.Throws<FormatException>(() => ResponseFileHelper.SplitCommandLine("\"hello world").ToArray());

[TestMethod]
public void SplitCommandLine_TabSeparatedTokens_SplitsOnTab()
Expand Down
Loading