From b39f57f6bc510214e50816ac22b71122c05a4d2c Mon Sep 17 00:00:00 2001 From: Nitin Kumar <59679977+lazysegtree@users.noreply.github.com> Date: Thu, 29 Jan 2026 12:32:15 +0530 Subject: [PATCH] fix: Add ci test for options_no_regex, and fix inconsistency between regex pattern and customer parser (#487) * chore(ci): Add test for options_no_regex * fix: Fix regex parsing for CXXOPTS_NO_REGEX --- include/cxxopts.hpp | 12 +++++------- test/CMakeLists.txt | 5 +++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index 1795169..537b2e7 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -730,7 +730,7 @@ inline ArguDesc ParseArgument(const char *arg, bool &matched) { argu_desc.arg_name.push_back(*pdata); pdata += 1; - while (isalnum(*pdata, std::locale::classic()) || *pdata == '-' || *pdata == '_') + while (isalnum(*pdata, std::locale::classic()) || *pdata == '-' || *pdata == '_' || *pdata == '.') { argu_desc.arg_name.push_back(*pdata); pdata += 1; @@ -757,13 +757,11 @@ inline ArguDesc ParseArgument(const char *arg, bool &matched) else if (strncmp(pdata, "-", 1) == 0) { pdata += 1; - argu_desc.grouping = true; - while (isalnum(*pdata, std::locale::classic())) - { - argu_desc.arg_name.push_back(*pdata); - pdata += 1; + if(isalnum(*pdata, std::locale::classic())) { + argu_desc.grouping = true; + argu_desc.arg_name = std::string(pdata); + matched = true; } - matched = !argu_desc.arg_name.empty() && *pdata == '\0'; } return argu_desc; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 91e27ec..757b081 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -22,6 +22,11 @@ add_executable(options_test main.cpp options.cpp) target_link_libraries(options_test cxxopts) add_test(options options_test) +add_executable(options_test_noregex main.cpp options.cpp) +target_link_libraries(options_test_noregex cxxopts) +target_compile_definitions(options_test_noregex PRIVATE CXXOPTS_NO_REGEX) +add_test(options_no_regex options_test_noregex) + # test if the targets are findable from the build directory add_test(find-package-test ${CMAKE_CTEST_COMMAND} -C ${CMAKE_BUILD_TYPE}