;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfUrlEscapeA (strURL, intFlags) hdlBB_pcchEscaped = BinaryAlloc (4) ; Allocate in/out size-buffer with size of DWORD. BinaryPoke4 (hdlBB_pcchEscaped, 0, 1) ; Poke smallest accepted size=1. hdlBB_pszEscaped = BinaryAlloc (1) ; Allocate test-buffer with smallest accepted size=1. intResult = DllCall ("SHLWAPI.DLL", long : "UrlEscapeA", lpstr : strURL, lpbinary : hdlBB_pszEscaped, lpbinary : hdlBB_pcchEscaped, long : intFlags) ; Error=-2147024809. intBufSize = BinaryPeek4 (hdlBB_pcchEscaped, 0) ; Get required number of characters for the conversion from size-buffer. hdlBB_pszEscaped = BinaryFree (hdlBB_pszEscaped) ; Free test-buffer. hdlBB_pszEscaped = BinaryAlloc (intBufSize) ; Allocate out-buffer with required size. BinaryEodSet (hdlBB_pszEscaped, intBufSize) ; Set out-buffer EOD to maximal size. intResult = DllCall ("SHLWAPI.DLL", long : "UrlEscapeA", lpstr : strURL, lpbinary : hdlBB_pszEscaped, lpbinary : hdlBB_pcchEscaped, long : intFlags) ; OK=0. strURL = BinaryPeekStr (hdlBB_pszEscaped, 0, intBufSize) ; Get converted string. hdlBB_pszEscaped = BinaryFree (hdlBB_pszEscaped) ; Free out-buffer. hdlBB_pcchEscaped = BinaryFree (hdlBB_pcchEscaped) ; Free size-buffer. Return strURL ;.......................................................................................................................................... ; This UDF "udfUrlEscapeA" converts characters in a URL that might be altered during transport ; across the Internet ("unsafe" characters) into their corresponding escape sequences. ;.......................................................................................................................................... ; Syntax: ; HRESULT UrlEscape( ; LPCTSTR pszURL, ; LPTSTR pszEscaped, ; LPDWORD pcchEscaped, ; DWORD dwFlags ; ); ;.......................................................................................................................................... ; dwFlags: ; URL_DONT_ESCAPE_EXTRA_INFO = 33554432 ; 0x02000000 ; Used only in conjunction with URL_ESCAPE_SPACES_ONLY to prevent the conversion of characters in the query (the portion of the URL following the first # or ? character encountered in the string). This flag should not be used alone, nor combined with URL_ESCAPE_SEGMENT_ONLY. ; URL_ESCAPE_PERCENT = 4096 ; 0x00001000 ; Convert any % character found in the segment section of the URL (that section falling between the server specification and the first # or ? character). By default, the % character is not converted to its escape sequence. Other unsafe characters in the segment are also converted normally. Combining this flag with URL_ESCAPE_SEGMENT_ONLY includes those % characters in the query portion of the URL. However, as the URL_ESCAPE_SEGMENT_ONLY flag causes the entire string to be considered the segment, any # or ? characters are also converted. This flag cannot be combined with URL_ESCAPE_SPACES_ONLY. ; URL_ESCAPE_SEGMENT_ONLY = 8192 ; 0x00002000 ; Indicates that pszURL contains only that section of the URL following the server component but preceeding the query. All unsafe characters in the string are converted. If a full URL is provided when this flag is set, all unsafe characters in the entire string are converted, including # and ? characters. Combine this flag with URL_ESCAPE_PERCENT to include that character in the conversion. This flag cannot be combined with URL_ESCAPE_SPACES_ONLY or URL_DONT_ESCAPE_EXTRA_INFO. ; URL_ESCAPE_SPACES_ONLY = 67108864 ; 0x04000000 ; Convert only space characters to their escape sequences, including those space characters in the query portion of the URL. Other unsafe characters are not converted to their escape sequences. This flag assumes that pszURL does not contain a full URL. It expects only the portions following the server specification. Combine this flag with URL_DONT_ESCAPE_EXTRA_INFO to prevent the conversion of space characters in the query portion of the URL. This flag cannot be combined with URL_ESCAPE_PERCENT or URL_ESCAPE_SEGMENT_ONLY. ; URL_ESCAPE_UNSAFE = 536870912 ; 0x20000000 ; ; See also: UrlEscape Function, http://msdn.microsoft.com/en-us/library/bb773774(VS.85).aspx ;.......................................................................................................................................... ; (c)Detlev Dalitz.20100127. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ; Test. URL_DONT_ESCAPE_EXTRA_INFO = 33554432 URL_ESCAPE_PERCENT = 4096 URL_ESCAPE_SEGMENT_ONLY = 8192 URL_ESCAPE_SPACES_ONLY = 67108864 URL_ESCAPE_UNSAFE = 536870912 ; URL_ESCAPE_SPACES_ONLY ; Only space characters are escaped. Other unsafe characters are ignored. ; Note: This flag expects the server portion of the URL to be omitted. ; ; Original = http://microsoft.com/test/t%e<s t.asp?url=/{ex% ample</abc.asp?frame=true#fr%agment ; Result = http://microsoft.com/test/t%e<s%20t.asp?url=/{ex%%20ample</abc.asp?frame=true#fr%agment ; ; Note: percent chars in the source string are doubled because of WinBatch substitution feature. strURL = "http://microsoft.com/test/t%%e<s t.asp?url=/{ex%% ample</abc.asp?frame=true#fr%%agment" strURlEscaped1 = udfUrlEscapeA (strURL, URL_ESCAPE_SPACES_ONLY) ; URL_ESCAPE_SPACES_ONLY | URL_DONT_ESCAPE_EXTRA_INFO ; Spaces in the segment are converted into their escape sequences, but spaces in the query are not. ; ; Original = http://microsoft.com/test/t%e<s t.asp?url=/{ex% ample</abc.asp?frame=true#fr%agment ; Result = http://microsoft.com/test/t%e<s%20t.asp?url=/{ex% ample</abc.asp?frame=true#fr%agment ; ; Note: percent chars in the source string are doubled because of WinBatch substitution feature. strURL = "http://microsoft.com/test/t%%e<s t.asp?url=/{ex%% ample</abc.asp?frame=true#fr%%agment" strURlEscaped2 = udfUrlEscapeA (strURL, URL_ESCAPE_SPACES_ONLY | URL_DONT_ESCAPE_EXTRA_INFO) ; URL_ESCAPE_PERCENT ; Here only the segment and query are supplied and the server component is ; omitted, although that is not required. Only the segment is considered. ; All unsafe characters plus the % character are converted in the segment. ; ; Original = http://microsoft.com/test/t%e<s t.asp?url=/{ex% ample</abc.asp?frame=true#fr%agment ; Result = http://microsoft.com/test/t%25e%3Cs%20t.asp?url=/{ex% ample</abc.asp?frame=true#fr%agment ; ; Note: percent chars in the source string are doubled because of WinBatch substitution feature. strURL = "http://microsoft.com/test/t%%e<s t.asp?url=/{ex%% ample</abc.asp?frame=true#fr%%agment" strURlEscaped3 = udfUrlEscapeA (strURL, URL_ESCAPE_PERCENT) ; URL_ESCAPE_SEGMENT_ONLY ; Note: This flag expects only the segment, omitting the server and query components. ; The / character is escaped as well as the usual unsafe characters. ; ; Original = test/t%e<s t.asp?url=/{ex% ample</abc.asp?frame=true#fr%agment ; Result = test%2Ft%e%3Cs%20t.asp%3Furl=%2F%7Bex%%20ample%3C%2Fabc.asp%3Fframe=true%23fr%agment ; ; Note: percent chars in the source string are doubled because of WinBatch substitution feature. strURL = "test/t%%e<s t.asp?url=/{ex%% ample</abc.asp?frame=true#fr%%agment" strURlEscaped4 = udfUrlEscapeA (strURL, URL_ESCAPE_SEGMENT_ONLY) ; URL_ESCAPE_UNSAFE ; ; Original = http://microsoft.com/test/t%e<s t.asp?url=/{ex% ample</abc.asp?frame=true#fr%agment ; Result = http://microsoft.com/test/t%e%3Cs%20t.asp?url=/{ex% ample</abc.asp?frame=true#fr%agment ; ; Note: percent chars in the source string are doubled because of WinBatch substitution feature. strURL = "http://microsoft.com/test/t%%e<s t.asp?url=/{ex%% ample</abc.asp?frame=true#fr%%agment" strURlEscaped5 = udfUrlEscapeA (strURL, URL_ESCAPE_UNSAFE) Exit