Bug 45198 - command line: macros in writer are not working if file name contains comma
Summary: command line: macros in writer are not working if file name contains comma
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
3.4.5 release
Hardware: x86-64 (AMD64) Linux (All)
: medium major
Assignee: Noel Power
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-24 12:47 UTC by cristi falcas
Modified: 2012-03-13 01:23 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description cristi falcas 2012-01-24 12:47:32 UTC
Due to bug 39298, I've made a small macro to replace some characters in documents.

If the filename of the document contains commas, the following error is displayed:
"Type: com.sun.star.lang.IllegalArgumentException
Message: URL seems to be an unsupported one"

The error is at line:
oDoc = StarDesktop.loadComponentFromURL(cURL, "_blank", 0, Array()) 

If I remove the comma from the filename, the macro is running correctly.

The command I'm using:

libreoffice --nocrashreport --nodefault --nologo --nofirststartwizard --norestore "macro:///Standard.Module1.ReplaceNBHyphenHTML(/home/cristi/A string, a comma.doc)"

The macro I'm using:

Function MakePropertyValue( Optional cName As String, Optional uValue ) _
   As com.sun.star.beans.PropertyValue
   Dim oPropertyValue As New com.sun.star.beans.PropertyValue
   If Not IsMissing( cName ) Then
      oPropertyValue.Name = cName
   EndIf
   If Not IsMissing( uValue ) Then
      oPropertyValue.Value = uValue
   EndIf
   MakePropertyValue() = oPropertyValue
End Function

Sub ReplaceNBHyphenHTML(cFile)
    cURL = ConvertToURL( cFile )
    GlobalScope.BasicLibraries.LoadLibrary("Tools")
    oDoc = StarDesktop.loadComponentFromURL(cURL, "_blank", 0, Array()) 

    oReplace = ThisComponent.createReplaceDescriptor()
	oReplace.SearchCaseSensitive = True
	oReplace.SearchString = chr(clng("&H2011"))
	oReplace.ReplaceString = "-"
	ThisComponent.ReplaceAll(oReplace)

    sFile = GetFileNameWithoutExtension(oDoc.url) + ".html"
    sURL = ConvertToURL( sFile )

    oDoc.storeAsURL(sURL, Array(MakePropertyValue("FilterName", "HTML (StarWriter)"),))
    oDoc.close( True )
End Sub
Comment 1 Rainer Bielefeld Retired 2012-01-24 22:42:30 UTC
@cristi falcas:
From where is information that comma should be allowed?
Does that problem really only affect macros related to writer?
Comment 2 cristi falcas 2012-01-25 01:23:00 UTC
I only tested with writer. There is another bug for calc (42308) about links to files that have commas in the name.

About the question if commas should be allowed, it most certainly is a bug, because it should support all filenames valid on the operating system.
Comment 3 sasha.libreoffice 2012-02-20 06:11:43 UTC
I have added into script this:
Sub Test
ReplaceNBHyphenHTML("/home/s/Hit,1.odt")
End Sub

When I start script from Basic IDE, it works correctly (file Hit,1.odt exist)

In this case (IDE) line
oDoc = StarDesktop.loadComponentFromURL(cURL, "_blank", 0, Array())
produces error with any name if file not exist. No problem with comma

When start from command line, problem appears. IMHO problem is with processing command line.

Information about loadComponentFromURL is here http://wiki.services.openoffice.org/wiki/Documentation/BASIC_Guide/StarDesktop
About command line is here http://wiki.services.openoffice.org/wiki/Framework/Article/Command_Line_Arguments
Comment 4 Rainer Bielefeld Retired 2012-03-06 09:38:20 UTC
@Noel:
Can you help? 
Please set Status to ASSIGNED and add yourself to "Assigned To" if you accept this Bug
Comment 5 Noel Power 2012-03-07 02:01:58 UTC
I'll look into it
Comment 6 Noel Power 2012-03-07 02:04:48 UTC
ok, marking this as notabug

',' is an argument delimiter, you need to quote the argument if you don't want it to get parsed into separate arguments e.g.

"macro:///Standard.Module1.ReplaceNBHyphenHTML(\"/home/cristi/A string, a comma.doc\")"

works perfectly well for me
Comment 7 sasha.libreoffice 2012-03-13 01:23:16 UTC
I have reproducible crash of LibreOffice when attempt to copy-paste this macro
Separate bugreport for this:
Bug 47265 - Basic IDE: LibreOffice crashes after adding new macro

Currently I afraid to start 3.6.0 master via gdb because computer hangs (too much RAM needed for symbols). But if it is important, I will do some attempts. Tell me if needed.