Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Address bar does not launch programs when path contains spaces and has parameters #15455

Closed
FieryRMS opened this issue May 23, 2024 · 4 comments · Fixed by #15459
Closed
Labels
bug Something isn't working 👀

Comments

@FieryRMS
Copy link
Contributor

Description

The Files app fails to find and launch programs if the path contains spaces and has parameters. Eg: running
D:\Folder With Spaces\program.exe param from the address bar, Files tries to "execute" D:\Folder with params With Spaces\program.exe param. The program still fails to run even if we explicitly specify the filename using quotes like,
"D:\Folder With Spaces\program.exe" param .

Steps To Reproduce

  1. create a batch file named test script.bat with the follow script:
    @echo off
    echo %*
  2. execute the script with some parameters through the address bar, e.g.: test script.bat param. The script fails to run.
  3. execute the script with quotes around the file name, e.g.: "test script.bat" param. The script fails to run.

Requirements

Expected outcome was that it should've been able to run when filename was explicitly specified with quotes. ("test script.bat" param)

This bug is caused by this part of the code,

if (trimmedInput.Contains(' '))
{
var positionOfBlank = trimmedInput.IndexOf(' ');
fileName = trimmedInput.Substring(0, positionOfBlank);
arguments = currentInput.Substring(currentInput.IndexOf(' '));
}
return await LaunchHelper.LaunchAppAsync(fileName, arguments, workingDir);

I propose to check if the user provided " to avoid ambiguity. If the first character is a " we look for the next " and use that as the delimiter instead. If we cannot find the second " we use the whole input as fileName. This behavior should be consistent with how cmd handles spaces.
Here is a possible implementation.

private static async Task<bool> LaunchApplicationFromPath(string currentInput, string workingDir)
{
	currentInput = currentInput.TrimStart();

	var positionOfDelimiter = currentInput.IndexOf(' ');
	if (currentInput.ElementAt(0) == '"')
		positionOfDelimiter = currentInput.IndexOf('"', 1);

	// if no spaces or doesn't start with a '"'
	if (positionOfDelimiter == -1)
		positionOfDelimiter = currentInput.Length - 1;

	positionOfDelimiter += 1; // include delimiter in fileName
	var fileName = currentInput.Substring(0, positionOfDelimiter);
	var arguments = currentInput.Substring(positionOfDelimiter);

	return await LaunchHelper.LaunchAppAsync(fileName, arguments, workingDir);
}

Files Version

3.4.1.0 - Dev

Windows Version

10.0.22631.3593

Log File

(not required)

@FieryRMS FieryRMS added the bug Something isn't working 👀 label May 23, 2024
@Josh65-2201
Copy link
Member

Thanks for the report, I've added this to the project board.

@yaira2
Copy link
Member

yaira2 commented May 23, 2024

@FieryRMS would you like to open a PR?

@FieryRMS
Copy link
Contributor Author

@FieryRMS would you like to open a PR?

sure, I'll be glad to

@yaira2
Copy link
Member

yaira2 commented May 24, 2024

@FieryRMS thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 👀
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants