Apache OpenOffice (AOO) Bugzilla – Issue 126731
Basic ConvertToURL fails to URL encode many characters
Last modified: 2015-12-20 16:03:13 UTC
OK: ConvertToURL("C:\Foo Bar") --> file:///C:/Foo&20Bar Fail: ConvertToURL("C:\Foo&Bar") --> file:///C:/Foo&Bar Expected: ConvertToURL("C:\Foo&Bar") --> file:///C:/Foo&26Bar Problem occurs with characters ! $ & ' ( ) * + , / : = @ ConvertToURL correctly encodes the follwing characters: <space> " # % ; ? [ \ ] { | } Reference: https://tools.ietf.org/html/rfc3986#page-12
Created attachment 85206 [details] Spreadsheet with user-defined Basic functions
Same with PyUNO: >>> s = '/foo & bar/concept.odt' >>> uno.systemPathToFileUrl(s) 'file:///foo%20&%20bar/concept.odt'
Sorry, the expected result for Expected: ConvertToURL("C:\Foo&Bar") is file:///C:/Foo%26Bar of course. This is a possible work-around for Basic coders: Function WorkAround_ConvertToURL(sysPath) As String Dim oSrv, a(), sURL$, nSplit&, sCode$, sProtocol$, sPathName$, sChar$, sRoot$ sURL = convertToURL(sysPath) a() = Array("!", "$", "&", "'", "(", ")", "*", "+", ",", ":", "=", "@") If getGUIType = 1 then nSplit = 11 else nSplit = 8 endif sProtocol = left(sURL, nSPlit) sPathName = mid(sURL, nSplit +1) oSrv = createUnoService("com.sun.star.sheet.FunctionAccess") For each sChar in a() if instr(sPathName, sChar) > 0 then sCode = "%"& hex(asc(sChar)) sPathName = oSrv.callFunction("SUBSTITUTE", Array(sPathName, sChar, sCode)) endif next WorkAround_ConvertToURL = sProtocol & sPathName End Function