core: fix crash with same name special category and keyword (#87)

---------

Co-authored-by: Vaxry <vaxry@vaxry.net>
This commit is contained in:
EvilLary 2025-11-28 19:52:41 +03:00 committed by GitHub
parent 3d66ec7c29
commit eb5be96aa0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 38 additions and 2 deletions

View file

@ -352,9 +352,13 @@ std::pair<bool, CParseResult> CConfig::configSetValueSafe(const std::string& com
found = true;
}
// probably a handler
if (!valueName.contains(":"))
return {false, result};
if (!found) {
for (auto& sc : impl->specialCategories) {
if (!valueName.starts_with(sc->name))
if (!valueName.starts_with(sc->name + ":"))
continue;
if (!sc->isStatic && std::string{std::any_cast<const char*>(sc->values[sc->key].getValue())} != impl->currentSpecialKey)

View file

@ -172,3 +172,14 @@ doABarrelRoll = woohoo, some, params # Funny!
flagsabc = test
#doSomethingFunny = 1, 2, 3, 4 # Funnier!
#testSpaces = abc , def # many spaces, should be trimmed
sameKeywordSpecialCat = pablo
sameKeywordSpecialCat:two:hola = rose
sameKeywordSpecialCat {
one {
some_size = 44
some_radius = 7.6
}
}

View file

@ -29,6 +29,7 @@ Hyprlang::CConfig* pConfig = nullptr;
std::string currentPath = "";
std::string ignoreKeyword = "";
std::string useKeyword = "";
std::string sameKeywordSpecialCat = "";
bool testHandlerDontOverrideValue = false;
static std::vector<std::string> categoryKeywordActualValues;
@ -75,6 +76,12 @@ static Hyprlang::CParseResult handleSource(const char* COMMAND, const char* VALU
return pConfig->parseFile(PATH.c_str());
}
static Hyprlang::CParseResult handleSameKeywordSpecialCat(const char* COMMAND, const char* VALUE) {
sameKeywordSpecialCat = VALUE;
return Hyprlang::CParseResult();
}
static Hyprlang::CParseResult handleTestHandlerDontOverride(const char* COMMAND, const char* VALUE) {
testHandlerDontOverrideValue = true;
@ -82,7 +89,6 @@ static Hyprlang::CParseResult handleTestHandlerDontOverride(const char* COMMAND,
return result;
}
static Hyprlang::CParseResult handleCustomValueSet(const char* VALUE, void** data) {
if (!*data)
*data = calloc(1, sizeof(int64_t));
@ -176,8 +182,17 @@ int main(int argc, char** argv, char** envp) {
config.addConfigValue("multiline", "");
config.registerHandler(&handleSameKeywordSpecialCat, "sameKeywordSpecialCat", {.allowFlags = false});
config.addSpecialCategory("sameKeywordSpecialCat", {.key = nullptr, .ignoreMissing = true, .anonymousKeyBased = false});
config.commence();
config.addSpecialCategory("sameKeywordSpecialCat:one", {.key = nullptr, .ignoreMissing = true});
config.addSpecialConfigValue("sameKeywordSpecialCat:one", "some_size", (Hyprlang::INT)10);
config.addSpecialConfigValue("sameKeywordSpecialCat:one", "some_radius", (Hyprlang::FLOAT)0.0);
config.addSpecialCategory("sameKeywordSpecialCat:two", {.key = nullptr, .ignoreMissing = true});
config.addSpecialConfigValue("sameKeywordSpecialCat:two", "hola", "");
config.addSpecialCategory("specialGeneric:one", {.key = nullptr, .ignoreMissing = true});
config.addSpecialConfigValue("specialGeneric:one", "value", (Hyprlang::INT)0);
config.addSpecialCategory("specialGeneric:two", {.key = nullptr, .ignoreMissing = true});
@ -216,6 +231,12 @@ int main(int argc, char** argv, char** envp) {
EXPECT(ignoreKeyword, "aaa");
EXPECT(useKeyword, "yes");
// test special category with same name as a keyword
EXPECT(sameKeywordSpecialCat, std::string_view{"pablo"});
EXPECT(std::any_cast<int64_t>(config.getSpecialConfigValue("sameKeywordSpecialCat:one", "some_size")), (Hyprlang::INT)44);
EXPECT(std::any_cast<float>(config.getSpecialConfigValue("sameKeywordSpecialCat:one", "some_radius")), (Hyprlang::FLOAT)7.6);
EXPECT(std::any_cast<const char*>(config.getSpecialConfigValue("sameKeywordSpecialCat:two", "hola")), std::string_view{"rose"});
// Test templated wrapper
auto T1 = Hyprlang::CSimpleConfigValue<Hyprlang::INT>(&config, "testInt");
auto T2 = Hyprlang::CSimpleConfigValue<Hyprlang::FLOAT>(&config, "testFloat");