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"
reproducible, the "name" edit field shows only the first part of the fieldname, e.g. "My" instead "My Field"
Reproduced back to
The Field dialog doesn't allow to insert spaces.
I guess the solution should be to replace spaces with another char when using macros...
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
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.
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.
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?
Good job guys ... appreciate all your efforts!
Just checking for an update and read my last post. Apologies, comes across as patronising which wasn't my intent.
Unfortunately, I cannot decide whether we allow all kind of chars in a user field, and restricting it breaks some existing tests.
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.
My problem is what kind of user fields should be allowed and which regressions (display errors arise)? Some examples (without quotes:
" a user field"
The odf-standard defines a user named range as a string which imho allows any combination of chars.