It is currently March 29th, 2024, 2:58 pm

[BUG?]Quotes persist in Section variable function

Report bugs with the Rainmeter application and suggest features.
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

[BUG?]Quotes persist in Section variable function

Post by death.crafter »

I was working on a custom plugin in C# where I wanted an array of strings from inline function as argument.

Now,

[&PluginMeasure:SomeFunction(String1, String2, String3)]

works fine but when we need a literal comma(,) in our string we need to put it inside quotes, e.g.

[&PluginMeasure:SomeFunction("String, with, a, comma", String2, String3)].

Now, the second one works but the strings persist when the arrays are "**marshalled" in C#.

For example if I want to return the first string, it is returned as

"String, with, a, comma."

, with the quotes intact.

So, is it intentional or a bug?

If you want I can post the plugin in question here.
**I don't know the technical details. Just that it converts the object between native and non-native code (source: MS Docs).
from the Realm of Death
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [BUG?]Quotes persist in Section variable function

Post by jsmorley »

death.crafter wrote: September 24th, 2021, 11:19 am I was working on a custom plugin in C# where I wanted an array of strings from inline function as argument.

Now,

[&PluginMeasure:SomeFunction(String1, String2, String3)]

works fine but when we need a literal comma(,) in our string we need to put it inside quotes, e.g.

[&PluginMeasure:SomeFunction("String, with, a, comma", String2, String3)].

Now, the second one works but the strings persist when the arrays are "**marshalled" in C#.

For example if I want to return the first string, it is returned as

"String, with, a, comma."

, with the quotes intact.

So, is it intentional or a bug?

If you want I can post the plugin in question here.
**I don't know the technical details. Just that it converts the object between native and non-native code (source: MS Docs).
Not sure. Did you try using [\0044] as a character reference for a comma in the string to see if that works correctly?
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: [BUG?]Quotes persist in Section variable function

Post by death.crafter »

jsmorley wrote: September 24th, 2021, 11:27 am Not sure. Did you try using [\0044] as a character reference for a comma in the string to see if that works correctly?
This works as expected but the comma isn't the problem.

C# function:

Code: Select all

[DllExport]
public static IntPtr Substitute(IntPtr data, int argc, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1)] string[] argv)
	{
		if (argc > 0)
		{
			List<string> arg = new List<string>();
			foreach (string str in argv) 
			{
				/*if (Regex.IsMatch(str, "^\".+\"$"))
                    		{
					arg.Add(Regex.Match(str, "^\"(.+)\"$").Groups[1].Value);
                    		}
                    		else if(Regex.IsMatch(str, "^\'.+\'$"))
                    		{
					arg.Add(Regex.Match(str, "^\'(.+)\'$").Groups[1].Value);
				}
                    		else
                    		{*/
						arg.Add(str);
                    		//}
			}
			if (arg.Count < 2) { return Marshal.StringToHGlobalUni(arg[0]);}
			if (arg.Count < 3) { arg[2] = "";}
			return Marshal.StringToHGlobalUni(arg[0].Replace(arg[1], arg[2]));
			}
		return IntPtr.Zero;
	}
The commented out part is the workaround for the possible bug.

But here is the skin:
PluginString_0.5.rmskin
You do not have the required permissions to view the files attached to this post.
from the Realm of Death
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [BUG?]Quotes persist in Section variable function

Post by jsmorley »

What I was saying was to use the character reference to avoid using "quotes" in the string.
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: [BUG?]Quotes persist in Section variable function

Post by death.crafter »

jsmorley wrote: September 24th, 2021, 11:53 am What I was saying was to use the character reference to avoid using "quotes" in the string.
[&PluginMeasure:SomeFunction(String[\0044] with[\0044] a[\0044] comma, String2, String3)]

works like:

[&PluginMeasure:SomeFunction(String, with, a, comma, String2, String3)]

Returned string would be: String and not String, with, a, comma

So this works as expected, or may be not if you think it should work other wise.

But I doubt any one would use [\0044] instead of a ,.
from the Realm of Death
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: [BUG?]Quotes persist in Section variable function

Post by death.crafter »

So is this a bug or normal behavior. I will keep the plugin as is (with the workaround) if so.
from the Realm of Death
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [BUG?]Quotes persist in Section variable function

Post by jsmorley »

death.crafter wrote: September 24th, 2021, 1:18 pm So is this a bug or normal behavior. I will keep the plugin as is (with the workaround) if so.
Well, given that we really have nobody on the development team that has a lot of experience with C# at the moment, I'm not sure there is a practical difference...
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: [BUG?]Quotes persist in Section variable function

Post by death.crafter »

jsmorley wrote: September 24th, 2021, 1:30 pm Well, given that we really have nobody on the development team that has a lot of experience with C# at the moment, I'm not sure there is a practical difference...
I don't think it's a c# problem.

The ConfigParser::Tokenize2 is including the paired punctuations some how.
Start in ConfigParser.cpp: https://github.com/rainmeter/rainmeter/blob/47c3ea7f611ecbd004811ed93ff42030c486d6d8/Library/ConfigParser.cpp#L1505

I don't know about c++ so can't say something for sure but it's not a problem regarding c# cause it just recieves what MeasurePlugin puts in the argument.

Also I think if a single punctuation is used, say

[&measure:function("String1, String2)]

then the the tokenizer passes the whole string as one argument and doesn't split it at comma. I don't know if it is expected behaviour or not but it shouldn't be.

May be try a c++ plugin that does the same thing as above. If you have time that is. Or I will try when I get back at my pc.

Thanks for your time though.
from the Realm of Death
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: [BUG?]Quotes persist in Section variable function

Post by death.crafter »

Okay here is a C++ plugin showing the same behavioir:

Code: Select all

#include <Windows.h>
#include "../../API/RainmeterAPI.h"

struct Measure
{
	Measure() {}
};

PLUGIN_EXPORT void Initialize(void** data, void* rm)
{
	Measure* measure = new Measure;
	*data = measure;
}

PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
{
	Measure* measure = (Measure*)data;
}

PLUGIN_EXPORT double Update(void* data)
{
	Measure* measure = (Measure*)data;
	return 0.0;
}

PLUGIN_EXPORT LPCWSTR Return(void* data, const int argc, const WCHAR* argv[])
{
	Measure* measure = (Measure*)data;
	return argv[0];
}

PLUGIN_EXPORT void Finalize(void* data)
{
	Measure* measure = (Measure*)data;
	delete measure;
}
Function in focus:

Code: Select all

PLUGIN_EXPORT LPCWSTR Return(void* data, const int argc, const WCHAR* argv[])
{
	Measure* measure = (Measure*)data;
	return argv[0];
}
Usage in focus:

Code: Select all

Text=[&ExamplePlugin:Return("String, with, comma", String2, String3)]
#CRLF#
[&ExamplePlugin:Return(String[\0044] with[\0044] comma, String2, String3)]
Example skin with plugin:
ExampleSkin_1.0.rmskin
Screenshot:
Screenshot 2021-09-25 200104.png
You do not have the required permissions to view the files attached to this post.
from the Realm of Death
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: [BUG?]Quotes persist in Section variable function

Post by death.crafter »

...

Just wanted to bump, cause it is really problematic.

When I do [&Plugin:Function('String')], I get 'String' and not String to work with. :(
from the Realm of Death