Page 1 of 1

String variable editing does not allow the "+"

Posted: Wednesday 12 February 2025 19:54
by Sunday
Version: 2024.7 (build 16355)
Platform: W10 pro Fr
Description: The GUI of the user variables editing doesn't display any character(s) "+" of string variables. Spaces are displayed instead. :| .

Does anyone have a tip ?

Re: String variable editing does not allow the "+"

Posted: Wednesday 12 February 2025 21:05
by HvdW
Restart your windows computer.
It seems Windows and your keyboard have a communication problem.

Re: String variable editing does not allow the "+"

Posted: Wednesday 12 February 2025 21:56
by willemd
HvdW wrote: Wednesday 12 February 2025 21:05 Restart your windows computer.
It seems Windows and your keyboard have a communication problem.
Did you try your own solution? I don't think this is the issue.

When I test, I have the same problem and this is probably because the + sign is a special character, maybe interpreted as a concatenate function, although one would then not expects a space instead but just nothing. Try adding a variable with value 123+456 as string and you will see.

I have tried various escape characters in front of the + sign but not found a solution yet.

Re: String variable editing does not allow the "+"

Posted: Wednesday 12 February 2025 23:38
by HvdW
You have a point here.

Code: Select all

        local testString = "123\\+456"
        domoticz.log('Test string with escaped +: ' .. testString, domoticz.LOG_DEBUG)
Doesn't give the desired result.

Code: Select all

local testString = "123" .. string.char(43) .. "456"
This one does.

Code: Select all

local testString = [[123+456]]
Too.

Re: String variable editing does not allow the "+"

Posted: Wednesday 12 February 2025 23:53
by waltervl
Use %2B
Eg

Code: Select all

plus%2Bplus
Should show 'plus+plus'

Re: String variable editing does not allow the "+"

Posted: Thursday 13 February 2025 7:12
by habahabahaba
I think the TS is saying about Setup -> More options -> User Variables.

direct "+" is not saving too.

But waltervl's solution is working.

Re: String variable editing does not allow the "+"

Posted: Friday 14 February 2025 11:31
by FlyingDomotic
Probably caused by using http(s) between UI and Domoticz ;-)

Re: String variable editing does not allow the "+"

Posted: Friday 14 February 2025 12:13
by Sunday
waltervl wrote: Wednesday 12 February 2025 23:53 Use %2B
Eg

Code: Select all

plus%2Bplus
Should show 'plus+plus'
Why does Domoticz's script encode a string type user variable that is saved as a string in the SQLite database? What is the point, if not to be able to enter certain characters in the GUI ?

bool CSQLHelper::UpdateUserVariable(const std::string& varname, const _eUsrVariableType eVartype, const std::string& varvalue, const bool eventtrigger, std::string& errorMessage)
{
if (!CheckUserVariable(eVartype, varvalue, errorMessage))
return false;

auto result = safe_query("SELECT ID FROM UserVariables WHERE (Name=='%q')", varname.c_str());
if (result.empty())
return false;

std::string sLastUpdate = TimeToString(nullptr, TF_DateTime);
std::string szVarValue = CURLEncode::URLDecode(varvalue);
safe_query(
"UPDATE UserVariables SET ValueType='%d', Value='%q', LastUpdate='%q' WHERE (Name=='%q')",
eVartype,
szVarValue.c_str(),
sLastUpdate.c_str(),
varname.c_str()
);
if (m_bEnableEventSystem)
{
uint64_t vId = std::stoull(result[0][0]);
if (eventtrigger)
m_mainworker.m_eventsystem.SetEventTrigger(vId, m_mainworker.m_eventsystem.REASON_USERVARIABLE, 0);
m_mainworker.m_eventsystem.UpdateUserVariable(vId, varname, (int)eVartype, szVarValue, sLastUpdate);
}
return true;
}

Re: String variable editing does not allow the "+"

Posted: Friday 14 February 2025 14:41
by waltervl
You are free to make a PR to the repository to fix the issue....

Re: String variable editing does not allow the "+"

Posted: Friday 14 February 2025 18:40
by Sunday
This is a bit complicated for me !

I am not an expert in computer science and I guess the guy who has programmed this was probably right to do it.
There is something strange into the script "httpclient\UrlEncode.cpp" because the characters "+&=?#%/:;,@[]`<>\^|~{}$!#?=&/" are "unsafe", BUT strangely the script erases them, whereas it should encode them to display them into the user variable in my opinion.

By the way, a user variable is not an url.

Who can study ?