Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table name not protected against spaces #1951

Open
1 of 5 tasks
ruirodrigues1971 opened this issue Jan 4, 2023 · 5 comments · May be fixed by #2046
Open
1 of 5 tasks

Table name not protected against spaces #1951

ruirodrigues1971 opened this issue Jan 4, 2023 · 5 comments · May be fixed by #2046

Comments

@ruirodrigues1971
Copy link

ruirodrigues1971 commented Jan 4, 2023

Read and complete the full issue template

Do not randomly delete sections. They are here for a reason.

Do you want to request a feature or report a bug?

  • Bug
  • Feature
  • Question

Did you test against the latest CI build?

  • Yes
  • No

If you answered No, please test with the latest development build first.

Version of ClosedXML

0.97.0

What is the current behavior?

Allows empty space in table names
image

What is the expected behavior or new feature?

When you give a name to a table the code protect against starting with number or repeated names, but don't protected against space
The expected behavior is to give an error

image

Is this a regression from the previous version?

I don't know is my first attempt to use the library

@NickNack2020
Copy link
Contributor

I haven't contributed to ClosedXML in a while, trying to get back into it, would be willing to work on this. Would the desired behavior here be to throw an exception?

@NickNack2020
Copy link
Contributor

NickNack2020 commented Mar 23, 2023

Alright, I looked into this, obviously it's fairly easy to add a check, but I don't want to without sign off from one of the main contributors. The reason being is, adding a check for a space, would actually result in a change in the existing behavior that might cause a backwards incompatibility for users.

Currently during workbook save when serializing the TablePartDefinitionXml there is a call to GetTableName which has a call to RemoveSpecialCharacters which is normalizing the table name by removing any spaces. This means the saved file is not corrupt.

For if example if I set the table name to "Table With Spaces" it will be saved as "TableWithSpaces"

Fixing this would mean we break existing users in the wild if they were relying on this behavior

Not fixing it means you have hidden side effects if you do a round trip. Meaning if you open the saved file you generated with ClosedXml you can't access the table by the name "Table With Spaces" you would have to know the internals stripped away spaces and would have to access it by the normalized named "TableWithSpaces"

@jahav what behavior would you prefer?

@vbjay
Copy link
Contributor

vbjay commented Mar 23, 2023

Make the get table by name functionality use the same functionality so that when table name with spaces or other weirdness is sent in, it fixes the key for the developer.

@ruirodrigues1971
Copy link
Author

In the scenario that I was using was important that the name is correct.
External System ---> table names with spaces ----> closedXML
Changing table names inside closedXML is a very dangerous solution in my opinion... The probability to think in every scenarios that the bad name (with spaces) can be used in the code can be huge...

I think the throwing error is the most correct. Is important the code has a coherent answer to dev errors. But this is my opinion.

@jahav
Copy link
Member

jahav commented Mar 23, 2023

@NickNack2020

I think it would be better to reject invalid name with an exception. Name of a table is not just an identifier, but it can also be used formulas structured references (e.g. SUM(SalesTable[Profit])).

I am in favour of simple, understandable interfaces and contracts and principle of least surprise. Having a name sanitizer inside is not in line with that.

I would therefore refuse any invalid table names. We already throw an exception There is already a table names 'Xyz' when if someone tries to add a table with duplicate name. This only enhances the contract to be correct.

Please add a note/mitigation about change to the https://github.com/ClosedXML/ClosedXML/blob/develop/docs/migrations/migrate-to-0.101.rst + info in XML doc.

Spec says

A string representing the name of the table. This is the name that shall be used in
formula references, and displayed in the UI to the spreadsheet user.
This name shall not have any spaces in it, and it shall be unique amongst all other
displayNames and definedNames in the workbook. The character lengths and
restrictions are the same as for definedNames. See SpreadsheetML Reference -
Workbook definedNames section for details

NickNack2020 added a commit to NickNack2020/ClosedXML that referenced this issue Apr 2, 2023
@NickNack2020 NickNack2020 linked a pull request Apr 2, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants