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

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

Open
w3lld0ne opened this issue Feb 8, 2024 · 4 comments
Open

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

w3lld0ne opened this issue Feb 8, 2024 · 4 comments

Comments

@w3lld0ne
Copy link

w3lld0ne commented Feb 8, 2024

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.

@phlptp
Copy link
Collaborator

phlptp commented Feb 8, 2024

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
Copy link
Collaborator

phlptp commented Feb 8, 2024

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

@phlptp
Copy link
Collaborator

phlptp commented Feb 8, 2024

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

@w3lld0ne
Copy link
Author

w3lld0ne commented Feb 8, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants