Bug 97998 - FILESAVE When saving file as DBF dollar signs in headers change to underscores
Summary: FILESAVE When saving file as DBF dollar signs in headers change to underscores
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
4.3.0.4 release
Hardware: x86-64 (AMD64) All
: medium minor
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-19 05:05 UTC by Michael Gaskov
Modified: 2017-06-25 05:35 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
Example of DBF containing '$'. (134 bytes, application/x-dbase)
2016-02-23 06:29 UTC, Michael Gaskov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Gaskov 2016-02-19 05:05:36 UTC
Steps to reproduce:
1. Create a new document.
2. Make a header in one of the columns (in cell A1, for instance). The header should contain the dollar sign ('$'), e.g. 'X$USERS,C,16'.
3. Save the document in dBase format (*.dbf). The charset does not matter.
4. Close the document and open it again.
5. The dollar sign changed to underscore ('_'). In the example above the header will read 'X_USERS,C,16'.

If a cell contains a dollar sign but it is not a column header, the sign stays there. Only the column headers are affected.

It is possible to change the underscore to the dollar sign by editing the DBF in Notepad for example. Such file will be opened by Calc normally and the headers will contain dollar signs. However, after saving this file, the dollar signs will again change to underscores.
Comment 1 raal 2016-02-21 18:38:46 UTC
I can confirm with Version: 5.2.0.0.alpha0+
Build ID: 91a7580e03d5b47c6e2513afce85ddee45e730b6
CPU Threads: 4; OS Version: Linux 4.2; UI Render: GL; 
TinderBox: Linux-rpm_deb-x86_64@70-TDF, Branch:master, Time: 2016-02-04_00:17:43

and LO 3.5

Are you sure that $ character is allowed in header? I tried other characters @#%%^&* and all are substitute by _
Comment 2 Michael Gaskov 2016-02-23 06:29:59 UTC
Created attachment 122894 [details]
Example of DBF containing '$'.
Comment 3 Michael Gaskov 2016-02-23 06:35:47 UTC
I've consulted the dBase format specifications (can be found here: http://web.archive.org/web/20150323061445/http://ulisse.elettra.trieste.it/services/doc/dbase/DBFstruct.htm#C1.2) and it does not contain any restrictions on header names. Moreover, it is possible to create a DBF file with '$' signs in headers (see attachment, I made it with LO Calc and then altered it with Notepad). Such files can be opened normally, headers change only when saving the file.
Comment 4 Buovjaga 2016-02-26 18:11:50 UTC
Ok, let's set to NEW then.
Comment 5 Julien Nabet 2017-06-11 11:47:32 UTC
Here's a straightforward patch:
diff --git a/sc/source/ui/docshell/docsh8.cxx b/sc/source/ui/docshell/docsh8.cxx
index fe715fa66cf6..8aabdad1215c 100644
--- a/sc/source/ui/docshell/docsh8.cxx
+++ b/sc/source/ui/docshell/docsh8.cxx
@@ -565,7 +565,7 @@ void lcl_GetColumnTypes(
             sal_Unicode c;
             for ( const sal_Unicode* p = aFieldName.getStr(); ( c = *p ) != 0; p++ )
             {
-                if ( rtl::isAsciiAlpha(c) || rtl::isAsciiDigit(c) || c == '_' )
+                if ( rtl::isAsciiAlpha(c) || rtl::isAsciiDigit(c) || c == '_' || c == '$')
                     aTmpStr += OUStringLiteral1(c);
                 else
                     aTmpStr += "_";


Lionel: with hexdump, I saw that exported file was dBaseIII (see http://opengrok.libreoffice.org/xref/core/connectivity/source/inc/dbase/DTable.hxx#dBaseIII)
I don't find any doc which indicates precisely filename constraints. I read about 10 characters max and just ascii. But I suppose you can't use any ascii character.
Any thoughts?
Comment 7 Buovjaga 2017-06-25 05:35:16 UTC
Julien is right.

http://www.okstate.edu/sas/v8/sashtml/accpc/z0214453.htm
"Filenames or field names start with a letter, and they can contain any combination of the letters A through Z, the digits 0 through 9, the colon (:) (in dBASE II field names only), and the underscore (_)."

https://devzone.advantagedatabase.com/dz/webhelp/Advantage8.1/mergedProjects/ace/intro/supported_file_formats.htm
"Field names in a DBF table are limited to just 10 characters and may contain only the letters a-z and A-Z, digits 0-9, and the underscore "_" character."

https://bz.apache.org/ooo/show_bug.cgi?id=39683#c11
"A field name has to consist of alphanumeric (ASCII upper case alpha letters
and digits) plus the underscore character."