Bug 121590 - Unable to alter or delete user fields containing spaces
Summary: Unable to alter or delete user fields containing spaces
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: UI (show other bugs)
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Not Assigned
Depends on:
Blocks: Fields Macro-UNOAPI
  Show dependency treegraph
Reported: 2018-11-21 14:13 UTC by libreoffice
Modified: 2021-10-12 10:02 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:
Regression By:

Document with code and button to reproduce the problem (9.88 KB, application/vnd.oasis.opendocument.text)
2018-11-21 14:13 UTC, libreoffice

Note You need to log in before you can comment on or make changes to this bug.
Description libreoffice 2018-11-21 14:13:28 UTC
Created attachment 146874 [details]
Document with code and button to reproduce the problem

If you create a user field in a macro where the name contains a space, the more fields dialog will not let you edit or delete the field.

Code to reproduce the bug:

vDoc = ThisComponent
sName = "My Field"
If vDoc.getTextFieldMasters().hasByName("com.sun.star.text.FieldMaster.User." & sName) Then
  vField = vDoc.getTextFieldMasters().getByName("com.sun.star.text.FieldMaster.User." & sName)
  vField.Content = "My Field Text"
  vField = vDoc.createInstance("com.sun.star.text.FieldMaster.User")
  vField.Name = sName
  vField.Content = "My Field Text Update"
End If
Comment 1 Oliver Brinzing 2018-11-21 18:42:12 UTC
reproducible, the "name" edit field shows only the first part of the fieldname, e.g. "My" instead "My Field"
Comment 2 Xisco Faulí 2018-11-22 09:57:08 UTC
Reproduced back to

LibreOffice 3.3.0 
OOO330m19 (Build:6)
tag libreoffice-

The Field dialog doesn't allow to insert spaces.
I guess the solution should be to replace spaces with another char when using macros...
Comment 3 Oliver Brinzing 2018-11-22 17:53:26 UTC
btw: there is a similar issue for named ranges in calc:

inserting named ranges with special characters, e.g. 
operators ':', '+', ... in name are allowed via api
Comment 4 Andreas Heinisch 2021-04-29 13:40:20 UTC
According to the documentation in http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html#__RefHeading__1419030_253892949 the name can be any variableName, which is "a string specifying the name of a variable".

The check in the dialog was inserted in the following commit https://github.com/LibreOffice/core/commit/4b920e0b45a42c55503dc03a7297733fb2cfb2a3, but unfortunately I cannot find the mentioned bug.

There even exists a file in https://git.libreoffice.org/core/+/f2039cdbd827d60b8e0dbfa2e1d02dbb276514d6%5E%21 which contains user fields including whitespaces and does get validated using a odf validator.

So we may allow whitespaces, and validate the field name when inserted via api.
Comment 5 Andreas Heinisch 2021-04-29 14:56:14 UTC
The only problem I see is that if a user opens a document containing field names including forbidden characters, they will be silently replaced? The same happens, if they are added via api.
Comment 6 Andreas Heinisch 2021-04-29 18:49:06 UTC
Tested now with a fix which tries to convert all the non allowed characters to underscores, but a couple of test documents contain user fields with special chars like whitespaces, backslashes etc.

Since the ODF allows user fields with strings, mabye we should change just the dialog edit field? Any opinions?
Comment 7 libreoffice 2021-04-29 22:05:14 UTC
Good job guys ... appreciate all your efforts!
Comment 8 libreoffice 2021-05-06 20:13:30 UTC
Just checking for an update and read my last post. Apologies, comes across as patronising which wasn't my intent.
Comment 9 Andreas Heinisch 2021-10-12 07:08:49 UTC
Unfortunately, I cannot decide whether we allow all kind of chars in a user field, and restricting it breaks some existing tests.
Comment 10 libreoffice 2021-10-12 09:55:55 UTC
I believe the text field in the UI should allow the user to change whatever text the field contains. Manipulating the text to satisfy the text fields shortcommings, in my mind, will lead to all kinds of problems.
Comment 11 Andreas Heinisch 2021-10-12 10:02:00 UTC
My problem is what kind of user fields should be allowed and which regressions (display errors arise)? Some examples (without quotes:

"  a user field"
"   "
"@#$%user field"

The odf-standard defines a user named range as a string which imho allows any combination of chars.