From 969cb076e5b76f2e823aeca1937a3e1f159812ee Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 15 May 2024 17:45:22 +0100 Subject: [PATCH] dynamic: fix dynamic variables being blocked by flag keywords fixes #45 --- src/config.cpp | 2 +- src/config.hpp | 2 +- tests/config/config.conf | 4 ++++ tests/parse/main.cpp | 3 +++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index bee4e64..5f02be7 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -620,7 +620,7 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) { if (!h.options.allowFlags && h.name != LHS) continue; - if (h.options.allowFlags && !LHS.starts_with(h.name)) + if (h.options.allowFlags && (!LHS.starts_with(h.name) || LHS.contains(':') /* avoid cases where a category is called the same as a handler */)) continue; ret = h.func(LHS.c_str(), RHS.c_str()); diff --git a/src/config.hpp b/src/config.hpp index 54674a1..f1011da 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -88,7 +88,7 @@ class CConfigImpl { Hyprlang::SConfigOptions configOptions; - void parseComment(const std::string& comment); + void parseComment(const std::string& comment); struct { bool noError = false; diff --git a/tests/config/config.conf b/tests/config/config.conf index 1feedd1..45a7b8d 100644 --- a/tests/config/config.conf +++ b/tests/config/config.conf @@ -75,6 +75,10 @@ specialAnonymous { value = 3 } +flagsStuff { + value = 2 +} + testCategory:testValueHex = 0xFFfFaAbB $RECURSIVE1 = a diff --git a/tests/parse/main.cpp b/tests/parse/main.cpp index 359757a..6970386 100644 --- a/tests/parse/main.cpp +++ b/tests/parse/main.cpp @@ -98,6 +98,7 @@ int main(int argc, char** argv, char** envp) { config.addConfigValue("testCategory:testColor1", (Hyprlang::INT)0); config.addConfigValue("testCategory:testColor2", (Hyprlang::INT)0); config.addConfigValue("testCategory:testColor3", (Hyprlang::INT)0); + config.addConfigValue("flagsStuff:value", (Hyprlang::INT)0); config.addConfigValue("myColors:pink", (Hyprlang::INT)0); config.addConfigValue("myColors:green", (Hyprlang::INT)0); config.addConfigValue("myColors:random", (Hyprlang::INT)0); @@ -170,6 +171,8 @@ int main(int argc, char** argv, char** envp) { EXPECT(std::any_cast(config.getConfigValue("testCategory:testValueHex")), (Hyprlang::INT)0xAABBCCDD); EXPECT(config.parseDynamic("testStringColon", "1:3:3:7").error, false); EXPECT(std::any_cast(config.getConfigValue("testStringColon")), std::string{"1:3:3:7"}); + EXPECT(config.parseDynamic("flagsStuff:value = 69").error, false); + EXPECT(std::any_cast(config.getConfigValue("flagsStuff:value")), (Hyprlang::INT)69); // test dynamic special config.addSpecialConfigValue("specialGeneric:one", "boom", (Hyprlang::INT)0);