mirror of
				https://github.com/chibicitiberiu/rainmeter-studio.git
				synced 2024-02-24 04:33:31 +00:00 
			
		
		
		
	Add support for [Measure:EscapeUrl] to perform URL encoding
This commit is contained in:
		@@ -75,4 +75,20 @@ void EscapeRegExp(std::wstring& str)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					** Escapes reserved URL characters.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					void EscapeUrl(std::wstring& str)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						size_t pos = 0;
 | 
				
			||||||
 | 
						while ((pos = str.find_first_of(L" !*'();:@&=+$,/?#[]", pos)) != std::wstring::npos)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							WCHAR buffer[3];
 | 
				
			||||||
 | 
							_snwprintf_s(buffer, _countof(buffer), L"%.2X", str[pos]);
 | 
				
			||||||
 | 
							str[pos] = L'%';
 | 
				
			||||||
 | 
							str.insert(pos + 1, buffer);
 | 
				
			||||||
 | 
							pos += 3;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}  // namespace StringUtil
 | 
					}  // namespace StringUtil
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,6 +38,8 @@ inline std::wstring WidenUTF8(const std::string& str) { return Widen(str.c_str()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void EscapeRegExp(std::wstring& str);
 | 
					void EscapeRegExp(std::wstring& str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void EscapeUrl(std::wstring& str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}  // namespace StringUtil
 | 
					}  // namespace StringUtil
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,6 +46,13 @@ public:
 | 
				
			|||||||
		EscapeRegExp(str);
 | 
							EscapeRegExp(str);
 | 
				
			||||||
		Assert::AreEqual(L"\\\\\\^\\$\\|\\(test\\)\\[\\{\\. ing\\+\\*\\?", str.c_str());
 | 
							Assert::AreEqual(L"\\\\\\^\\$\\|\\(test\\)\\[\\{\\. ing\\+\\*\\?", str.c_str());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						TEST_METHOD(TestEscapeUrl)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							std::wstring str = L" !*'();:@test&=+$,/?#[ing]";
 | 
				
			||||||
 | 
							EscapeUrl(str);
 | 
				
			||||||
 | 
							Assert::AreEqual(L"%20%21%2A%27%28%29%3B%3A%40test%26%3D%2B%24%2C%2F%3F%23%5Bing%5D", str.c_str());
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}  // namespace StringUtil
 | 
					}  // namespace StringUtil
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -237,7 +237,8 @@ bool ConfigParser::GetSectionVariable(std::wstring& strVariable, std::wstring& s
 | 
				
			|||||||
		Percentual,
 | 
							Percentual,
 | 
				
			||||||
		Max,
 | 
							Max,
 | 
				
			||||||
		Min,
 | 
							Min,
 | 
				
			||||||
		EscapeRegExp
 | 
							EscapeRegExp,
 | 
				
			||||||
 | 
							EscapeUrl
 | 
				
			||||||
	} valueType = ValueType::Raw;
 | 
						} valueType = ValueType::Raw;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (isKeySelector)
 | 
						if (isKeySelector)
 | 
				
			||||||
@@ -254,6 +255,10 @@ bool ConfigParser::GetSectionVariable(std::wstring& strVariable, std::wstring& s
 | 
				
			|||||||
		{
 | 
							{
 | 
				
			||||||
			valueType = ValueType::EscapeRegExp;
 | 
								valueType = ValueType::EscapeRegExp;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							else if (_wcsicmp(selectorSz, L"EscapeUrl") == 0)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								valueType = ValueType::EscapeUrl;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
@@ -299,6 +304,12 @@ bool ConfigParser::GetSectionVariable(std::wstring& strVariable, std::wstring& s
 | 
				
			|||||||
			StringUtil::EscapeRegExp(strValue);
 | 
								StringUtil::EscapeRegExp(strValue);
 | 
				
			||||||
			return true;
 | 
								return true;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							else if (valueType == ValueType::EscapeUrl)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								strValue = measure->GetStringValue();
 | 
				
			||||||
 | 
								StringUtil::EscapeUrl(strValue);
 | 
				
			||||||
 | 
								return true;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		int scale = 1;
 | 
							int scale = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user