mirror of
https://github.com/hyprwm/hyprlang.git
synced 2025-12-20 03:50:02 +01:00
core: fix crash with same name special category and keyword (#87)
--------- Co-authored-by: Vaxry <vaxry@vaxry.net>
This commit is contained in:
parent
3d66ec7c29
commit
eb5be96aa0
3 changed files with 38 additions and 2 deletions
|
|
@ -352,9 +352,13 @@ std::pair<bool, CParseResult> CConfig::configSetValueSafe(const std::string& com
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// probably a handler
|
||||||
|
if (!valueName.contains(":"))
|
||||||
|
return {false, result};
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
for (auto& sc : impl->specialCategories) {
|
for (auto& sc : impl->specialCategories) {
|
||||||
if (!valueName.starts_with(sc->name))
|
if (!valueName.starts_with(sc->name + ":"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!sc->isStatic && std::string{std::any_cast<const char*>(sc->values[sc->key].getValue())} != impl->currentSpecialKey)
|
if (!sc->isStatic && std::string{std::any_cast<const char*>(sc->values[sc->key].getValue())} != impl->currentSpecialKey)
|
||||||
|
|
|
||||||
|
|
@ -172,3 +172,14 @@ doABarrelRoll = woohoo, some, params # Funny!
|
||||||
flagsabc = test
|
flagsabc = test
|
||||||
#doSomethingFunny = 1, 2, 3, 4 # Funnier!
|
#doSomethingFunny = 1, 2, 3, 4 # Funnier!
|
||||||
#testSpaces = abc , def # many spaces, should be trimmed
|
#testSpaces = abc , def # many spaces, should be trimmed
|
||||||
|
|
||||||
|
sameKeywordSpecialCat = pablo
|
||||||
|
|
||||||
|
sameKeywordSpecialCat:two:hola = rose
|
||||||
|
|
||||||
|
sameKeywordSpecialCat {
|
||||||
|
one {
|
||||||
|
some_size = 44
|
||||||
|
some_radius = 7.6
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ Hyprlang::CConfig* pConfig = nullptr;
|
||||||
std::string currentPath = "";
|
std::string currentPath = "";
|
||||||
std::string ignoreKeyword = "";
|
std::string ignoreKeyword = "";
|
||||||
std::string useKeyword = "";
|
std::string useKeyword = "";
|
||||||
|
std::string sameKeywordSpecialCat = "";
|
||||||
bool testHandlerDontOverrideValue = false;
|
bool testHandlerDontOverrideValue = false;
|
||||||
static std::vector<std::string> categoryKeywordActualValues;
|
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());
|
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) {
|
static Hyprlang::CParseResult handleTestHandlerDontOverride(const char* COMMAND, const char* VALUE) {
|
||||||
testHandlerDontOverrideValue = true;
|
testHandlerDontOverrideValue = true;
|
||||||
|
|
||||||
|
|
@ -82,7 +89,6 @@ static Hyprlang::CParseResult handleTestHandlerDontOverride(const char* COMMAND,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Hyprlang::CParseResult handleCustomValueSet(const char* VALUE, void** data) {
|
static Hyprlang::CParseResult handleCustomValueSet(const char* VALUE, void** data) {
|
||||||
if (!*data)
|
if (!*data)
|
||||||
*data = calloc(1, sizeof(int64_t));
|
*data = calloc(1, sizeof(int64_t));
|
||||||
|
|
@ -176,8 +182,17 @@ int main(int argc, char** argv, char** envp) {
|
||||||
|
|
||||||
config.addConfigValue("multiline", "");
|
config.addConfigValue("multiline", "");
|
||||||
|
|
||||||
|
config.registerHandler(&handleSameKeywordSpecialCat, "sameKeywordSpecialCat", {.allowFlags = false});
|
||||||
|
config.addSpecialCategory("sameKeywordSpecialCat", {.key = nullptr, .ignoreMissing = true, .anonymousKeyBased = false});
|
||||||
|
|
||||||
config.commence();
|
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.addSpecialCategory("specialGeneric:one", {.key = nullptr, .ignoreMissing = true});
|
||||||
config.addSpecialConfigValue("specialGeneric:one", "value", (Hyprlang::INT)0);
|
config.addSpecialConfigValue("specialGeneric:one", "value", (Hyprlang::INT)0);
|
||||||
config.addSpecialCategory("specialGeneric:two", {.key = nullptr, .ignoreMissing = true});
|
config.addSpecialCategory("specialGeneric:two", {.key = nullptr, .ignoreMissing = true});
|
||||||
|
|
@ -216,6 +231,12 @@ int main(int argc, char** argv, char** envp) {
|
||||||
EXPECT(ignoreKeyword, "aaa");
|
EXPECT(ignoreKeyword, "aaa");
|
||||||
EXPECT(useKeyword, "yes");
|
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
|
// Test templated wrapper
|
||||||
auto T1 = Hyprlang::CSimpleConfigValue<Hyprlang::INT>(&config, "testInt");
|
auto T1 = Hyprlang::CSimpleConfigValue<Hyprlang::INT>(&config, "testInt");
|
||||||
auto T2 = Hyprlang::CSimpleConfigValue<Hyprlang::FLOAT>(&config, "testFloat");
|
auto T2 = Hyprlang::CSimpleConfigValue<Hyprlang::FLOAT>(&config, "testFloat");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue