It is currently October 15th, 2024, 8:41 am

New :EncodeURL Section Variable parameter

Changes made during the Rainmeter 3.1 beta cycle.
User avatar
jsmorley
Developer
Posts: 22856
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

New :EncodeURL Section Variable parameter

Post by jsmorley »

We have added a new :EncodeURL measure section variable parameter. This can be used to automatically URL-Encode parts of a URL string you plan to use with WebParser, calls to external programs that take a URL as a parameter, or anywhere else you need to encode parts of a URL before using it.

Caution: It is almost never the right answer to just encode the entire URL. The point of URL-encoding is to encode reserved characters that might confuse the process reading and using the URL. It is similar in concept to escaping reserved characters to use them as a literal in regular expression. You however do not want to encode things that are reserved characters in a URL but are in fact being used for their intended purpose.

Example:

Code: Select all

[MeasureName]
Measure=String
String=John:Doe

[MeasurePass]
Measure=String
String=A?17b@ml=9

[MeasureWebParser]
Measure=Plugin
Plugin=WebParser
URL=https://[&MeasureName:EncodeURL]:[&MeasurePass:EncodeURL]@gmail.google.com/gmail/feed/atom
RegExp="(?siU)^(.*)$"
DynamicVariables=1
Let's look at this for a second. Our gmail account name is John:Doe and our nice strong password is A?17b@ml=9. This could potentially give WebParser fits, as : ? @ and = are all reserved characters with a special meaning on a URL.

So what we are doing is using two String measures to hold our name and password. Then we use those measures in the URL for WebParser using the [&Measure:EncodeURL] syntax. The "&" is how we dynamically use the value of a measure in the URL of a WebParser measure, and the ":EncodeURL" will encode those reserved characters in our name and password, while not interfering with the normal use of ":" and "@" in the URL.

What this is doing under the covers is:

URL=https://John%3ADoe:A%3F17b%40ml%3D9@gmail.google.com/gmail/feed/atom
User avatar
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

Re: New :EncodeURL Section Variable parameter

Post by moshi »

i guess this is limited to just a few characters?

i tried German umlauts and Russian, but both didn't work. would be nice if they would, for example to use with Google Maps geocoding api.
User avatar
jsmorley
Developer
Posts: 22856
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: New :EncodeURL Section Variable parameter

Post by jsmorley »

It handles the following characters that can have a special meaning in a URL, and may cause the URL to be improperly parsed:

! * ' ( ) ; : @ & = + $ , / ? # [ ]
User avatar
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

Re: New :EncodeURL Section Variable parameter

Post by moshi »

i wish it could do more. to illustrate what i mean:

here's an older skin of mine: http://customize.org/rainmeter/skins/91166
entering Köln(German name of the city of Cologne) for example does not work, K%C3%B6ln on the other hand works fine.

personally i hope this is just a first step and you guys plan to add more functionality like decoding and support for UTF-en/decoding.