It is currently November 29th, 2021, 5:06 am

URL Encode - Percent Encode

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

URL Encode - Percent Encode

Post by jsmorley »

We have made changes to two different parts of Rainmeter, to better support URL-Encoding, also known as Percent-Encoding, when you are passing a URL to WebParser.

The first is in the :EncodeURL section variable parameter. This will now encode all characters that are not in the "unreserved" or URL-safe set of:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~

All other characters in the measure value will be percent-encoded.

Code: Select all

[MeasureString]
Measure=String
String=I live in München

[MeasureWebParser]
Measure=WebParser
URL=https://somesite.com?search=[&MeasureString:EncodeURL]
DynamicVariables=1
The result, sent to the remote site, would be:

https://somesite.com?search=I%20live%20in%20M%C3%BCnchen


The second is in the URL option of WebParser. This will now automatically and transparently encode the URL with the following rules:

Encoding will only take place on characters after the protocol://host/path/ portion of the URL.
Encoding will take place on any characters that are not either:

Unreserved URL-safe characters:
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~
Reserved URL-delimiter characters:
!*'();:@&=+$,/?%#[]

https://somesite.com?search=I live in München
https://somesite.com would not be encoded.
? and = would not be encoded.

Code: Select all

[MeasureWebParser]
Measure=WebParser
URL=https://somesite.com?search=I live in München
The result, sent to the remote site, would be:

https://somesite.com?search=I%20live%20in%20M%C3%BCnchen
Mr Muffin
Posts: 7
Joined: September 8th, 2018, 2:48 pm

Re: URL Encode - Percent Encode

Post by Mr Muffin »

Does this work with japaneese characters?
I'm trying to get kanji into dictionary's URL yet it converts to empty string

Code: Select all

[MeasureSite]
Measure=Plugin
Plugin=WebParser
CodePage=20932
URL=http://www.kanji-a-day.com/
RegExp=(?siU)<div class="glyph">\s*([^\s]{1})\s*</div>
UpdateRate=3600

[Kanji]
Measure=Plugin
Plugin=WebParser
URL=[MeasureSite]
StringIndex=1

[ok]
Measure = String
String = [&Kanji:EncodeURL]

[KanjiDictionary]
Measure=Plugin
Plugin=WebParser
URL=https://jisho.org/search/[ok]%20%23kanji
RegExp=(?siU)<dl class="dictionary_entry kun_yomi">.\s*<dt>Kun:</dt>.\s*<dd class="kanji-details__main-readings-list" lang="ja">(.*)</div>
Debug=2
Image
I have 4.4 Beta Release - r3412
User avatar
balala
Rainmeter Sage
Posts: 13497
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: URL Encode - Percent Encode

Post by balala »

Mr Muffin wrote: February 8th, 2021, 8:21 pm Does this work with japaneese characters?
I'm trying to get kanji into dictionary's URL yet it converts to empty string
  • Add a DynamicVariables=1 option to the [ok] and [KanjiDictionary] measures, because both are using section variables ([&Kanji:EncodeURL] on the [ok] measure and [ok] in the [KanjiDictionary] measure) and in such cases you have to set on the dynamic variables.
  • Remove the & sign from the [&Kanji:EncodeURL] section variable, because it's not needed, but add it to the [ok] section variable into the URL option of the [KanjiDictionary] measure (URL=https://jisho.org/search/[&ok]%20%23kanji).
  • The [KanjiDictionary] has to be updated when the [MeasureSite] (and its child measure) gets value. To do this add the FinishAction=[!CommandMeasure "KanjiDictionary" "Update"] option into the [MeasureSite] measure.
Mr Muffin
Posts: 7
Joined: September 8th, 2018, 2:48 pm

Re: URL Encode - Percent Encode

Post by Mr Muffin »

It does work now, thank you!
Just one more question:
I've set UpdateRate=3600 for booth WebParsers but with Debug=2 in [KanjiDictionary] I get a log about debug file every second or so. Should it be like that?
User avatar
balala
Rainmeter Sage
Posts: 13497
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: URL Encode - Percent Encode

Post by balala »

Mr Muffin wrote: February 9th, 2021, 2:37 pm It does work now, thank you!
I'm glad.
Mr Muffin wrote: February 9th, 2021, 2:37 pm Just one more question:
I've set UpdateRate=3600 for booth WebParsers but with Debug=2 in [KanjiDictionary] I get a log about debug file every second or so. Should it be like that?
The UpdateRate sets the period on which the measure connects to the online resource. The measure itself updates on each update cycle of the skin, just doesn't connects online to the resource, only after the time set on the UpdateRate option. So yes, it has to be like that.