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

Clean up export filenames for Excel compatibility #22969

Open
wants to merge 4 commits into
base: 5.x-dev
Choose a base branch
from
Open

Conversation

mneudert
Copy link
Member

Description:

The current (CSV) exports can contain unicode characters like &thsp; ("thin space"), preventing them from being openend in some programs like Excel.

A replacement of "special dashes" and "special whitespace" with their ASCII representation should fix that problem. Additionaly some other reserved characters like <> are now being removed from both report exports and scheduled report email attachment filenames.

Refs DEV-18832

Review

@mneudert mneudert added Bug For errors / faults / flaws / inconsistencies etc. Needs Review PRs that need a code review labels Jan 23, 2025
@mneudert mneudert added this to the 5.3.0 milestone Jan 23, 2025
@mneudert mneudert requested a review from a team January 23, 2025 13:53
@nathangavin
Copy link
Contributor

Tested the new function locally, can confirm that the new function behaves as expected. Was unable to replicate the wider issue on my Windows machine, my version of excel seems to handle these filenames correctly.

["control\x00\x09\x0A\x7Fcharacters", 'controlcharacters'],
['  spaces are trimmed  ', 'spaces are trimmed'],
['unicode    spaces', 'unicode spaces'],
['unicode‒–—dashes', 'unicode---dashes'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a couple more tests, such as a legal file name that isn't changed, and other special characters such as multi-byte unicode characters, like Chinese?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some examples generated from the report export feature. Let me know if there are any more variants/special characters we should add.


// https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file
$filename = preg_replace('~[<>:"/\\\\|?*]~', '', $filename);
$filename = preg_replace('~\p{Cc}~u', '', $filename);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps another comment explaining what these Regex statements mean, more than just a link?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More links and comments added 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. Needs Review PRs that need a code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants