CLI11 icon indicating copy to clipboard operation
CLI11 copied to clipboard

"Unrecognized escape sequence" after update to v2.4.0/v2.4.1

Open w3lld0ne opened this issue 1 year ago • 4 comments

After v2.4.0 update I receive Exception: "unrecognized escape sequence \a in C:\testdir\aaa.txt" on the following example code:

int main()
{
	std::string filePath;

	CLI::App cliApp("test");
	cliApp.add_option("file,-f,--file", filePath);

	try
	{
		cliApp.parse("-f \"C:\\testdir\\aaa.txt\"");
		printf("OK! Parsed file path: \"%s\"\n", filePath.c_str());
	}
	catch (const std::exception& e)
	{
		printf("Exception: \"%s\"\n", e.what()); // e.what() = "unrecognized escape sequence \a in C:\testdir\aaa.txt"
	}

	(void)getchar();
	return 0;
}

It is probably related to #970. When I compile with CLI11 version from this commit, everything works fine (displays OK! Parsed file path: "C:\testdir\aaa.txt").

I've tried to use new transformer ->transform(CLI::EscapedString), but no difference.

Win11 23H2, VS2022 17.8.6, C++20, file is in UTF-8.

P.S. Parsing a vector of args works fine on v2.4.1:

std::vector<std::string> args;
args.push_back("C:\\testdir\\aaa.txt");
args.push_back("-f");

cliApp.parse(args);

but a fix to std::string overload would be nice.

w3lld0ne avatar Feb 08 '24 16:02 w3lld0ne

The escape sequence handling was changed from non-existent to matching the rules used in toml file processing. Entirely possible there are some bugs in that as of yet.

you can probably try cliApp.parse("-f 'C:\\testdir\\aaa.txt'"); in this case to turn off the escape sequence parsing in this case

phlptp avatar Feb 08 '24 16:02 phlptp

Also maybe should add an app level option to disable escape sequence parsing

phlptp avatar Feb 08 '24 16:02 phlptp

the escape processing only happens by default on config files and the single string parse and split in strings surrounded by double quotes.

phlptp avatar Feb 08 '24 17:02 phlptp

you can probably try cliApp.parse("-f 'C:\\testdir\\aaa.txt'"); in this case

Thanks, changing \"text\" to 'text' worked. Also, app-level option for controlling the behaviour is a good idea!

w3lld0ne avatar Feb 08 '24 17:02 w3lld0ne