Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds filename sanitization to the DSpace Submission Service (DSS) SQS message generation to prevent DSpace publications that later fail to download due to problematic Unicode characters in bitstream names.
Changes:
- Sanitize
BitstreamNamevalues inSqsMessage#map_filesby normalizing Unicode (NFC) and removing/replacing known problematic invisible/dash characters. - Add unit tests covering normalization/removal/replacement behavior and an end-to-end assertion that sanitized filenames appear in
map_filesoutput. - Minor rubocop-driven refactors and small readability tweaks (e.g., numeric literals and degree-type predicate).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| app/models/sqs_message.rb | Sanitizes filenames used as BitstreamName before sending DSS payloads; minor readability tweaks. |
| test/models/sqs_message_test.rb | Adds tests for new sanitization behavior and reformats existing assertions. |
Suppressed comments (1)
test/models/sqs_message_test.rb:212
- The filename used to simulate a decomposed accent is constructed as
"garcía\u0301_thesis.pdf", which applies the combining acute accent to the precedinga(producingá) and leaves the precomposedíunchanged. After NFC normalization this would becomegarcíá_thesis.pdf, so the assertion expectinggarcía_thesis.pdfis inconsistent. Build the decomposed input deterministically from the intended NFC string (e.g.,.unicode_normalize(:nfd)).
# Attach file with decomposed unicode
@thesis.files.attach(io: File.open(f), filename: "garcía\u0301_thesis.pdf")
@thesis.files.last.purpose = 'thesis_pdf'
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Why these changes are being introduced: An end user reported that they could not download a file from DSpace. We learned that this was due to a decomposed unicode character, and found an additional 9 theses that were broken due to filenames with zero-width whitespace and en-dash characters. We've fixed the 10 published theses in ETD, but we need a way to proactively address this in the future. Relevant ticket(s): - [ETD-703](https://mitlibraries.atlassian.net/browse/ETD-703) - [ETD-702](https://mitlibraries.atlassian.net/browse/ETD-702) How this addresses that need: This adds to the SQS Message model a method that sanitizes filenames by removing the characters mentioned above, plus a few other potential culprits that we've not yet seen. (See side effects.) It avoids the more aggressive approach of changing filenames via a lifecycle hook. That option was considered, but a lower-intervention method seemed preferable. Side effects of this change: This makes a few assumptions about potential problematic characters that we've not yet seen in the wild (e.g., hidden directional characters and dash variants other than en-dash). It felt useful to be proactive about this.
Running this as a separate commit because it touches several lines of code unrelated to the previous commit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why these changes are being introduced:
An end user reported that they could not download
a file from DSpace. We learned that this was
due to a decomposed unicode character, and found
an additional 9 theses that were broken due to
filenames with zero-width whitespace and en-dash
characters.
We've fixed the 10 published theses in ETD, but
we need a way to proactively address this in the
future.
Relevant ticket(s):
How this addresses that need:
This adds to the SQS Message model a method that
sanitizes filenames by removing the characters
mentioned above, plus a few other potential
culprits that we've not yet seen. (See side
effects.)
It avoids the more aggressive approach of changing
filenames via a lifecycle hook. That option was
considered, but a lower-intervention method
seemed preferable.
Side effects of this change:
This makes a few assumptions about potential
problematic characters that we've not yet seen
in the wild (e.g., hidden directional characters
and dash variants other than en-dash). It felt
useful to be proactive about this.
Developer
Accessibility
New ENV
Approval beyond code review
Additional context needed to review
I ran rubocop in its own commit because it updated a lot of unrelated lines of code. It might be useful to review the commits separately.
Code Reviewer
Code
added technical debt.
Documentation
(not just this pull request message).
Testing