From 245e456b44fdd83e47441fa2cda9c6b59875cd2e Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Thu, 20 Nov 2025 23:42:14 +0300 Subject: [PATCH] settings(parse): force trailing suffix when already used it once prevent ambiguous specs when parsing native durations, which are implicitly used by default for numbers without suffixes --- code/espurna/types.cpp | 4 ++++ code/test/unit/src/settings/settings.cpp | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/code/espurna/types.cpp b/code/espurna/types.cpp index b8dea724..3b559e93 100644 --- a/code/espurna/types.cpp +++ b/code/espurna/types.cpp @@ -383,6 +383,10 @@ update_floating: update_decimal: { + if ((last != Type::Unknown) && (type == Type::Unknown)) { + goto reset; + } + const auto result = parseUnsigned(token, 10); if (result.ok) { // num and den are constexpr and bound to ratio types, so duration cast has to happen manually diff --git a/code/test/unit/src/settings/settings.cpp b/code/test/unit/src/settings/settings.cpp index 95b00910..eb94b837 100644 --- a/code/test/unit/src/settings/settings.cpp +++ b/code/test/unit/src/settings/settings.cpp @@ -221,6 +221,11 @@ void test_parse_duration_spec() { } void test_parse_fail_duration_spec() { + test_parse_fail("1000us100"); + test_parse_fail("100s50"); + test_parse_fail("ms100"); + test_parse_fail("s200"); + test_parse_fail("u300"); test_parse_fail("123ui"); test_parse_fail("123s456sm"); test_parse_fail("456s\x01\\789uu");