Issue 126731 - Basic ConvertToURL fails to URL encode many characters
Summary: Basic ConvertToURL fails to URL encode many characters
Status: UNCONFIRMED
Alias: None
Product: App Dev
Classification: Unclassified
Component: scripting (show other issues)
Version: 4.1.2
Hardware: All All
: P5 (lowest) Normal
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-12-11 13:58 UTC by Andreas Säger
Modified: 2015-12-20 16:03 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
Spreadsheet with user-defined Basic functions (19.80 KB, application/x-zip)
2015-12-11 13:59 UTC, Andreas Säger
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description Andreas Säger 2015-12-11 13:58:23 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
Comment 1 Andreas Säger 2015-12-11 13:59:43 UTC
Created attachment 85206 [details]
Spreadsheet with user-defined Basic functions
Comment 2 Andreas Säger 2015-12-11 17:18:33 UTC
Same with PyUNO:
>>> s = '/foo & bar/concept.odt'
>>> uno.systemPathToFileUrl(s)
'file:///foo%20&%20bar/concept.odt'
Comment 3 Andreas Säger 2015-12-20 16:03:13 UTC
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