#11395 closed enhancement (fixed)
Replace unicode control codes with spaces in attachment filename
Reported by: | Ryan J Ollos | Owned by: | Jun Omae |
---|---|---|---|
Priority: | normal | Milestone: | 1.1.3 |
Component: | attachment | Version: | |
Severity: | normal | Keywords: | unicode control codes |
Cc: | Ryan J Ollos | Branch: | |
Release Notes: |
Unicode control codes are replaced with spaces in attachment filenames. |
||
API Changes: | |||
Internal Changes: |
Description (last modified by )
It was discussed on the mailing list that control codes in attachment filename should be replaced with whitespaces.
Attachments (1)
Change History (13)
comment:1 by , 11 years ago
Description: | modified (diff) |
---|
comment:3 by , 11 years ago
Milestone: | next-stable-1.0.x → 1.0.3 |
---|---|
Owner: | set to |
Status: | new → assigned |
comment:4 by , 10 years ago
Milestone: | 1.0.3 → 1.1.3 |
---|---|
Release Notes: | modified (diff) |
Resolution: | → fixed |
Status: | assigned → closed |
It seemed least risky to finally push this to the trunk. Committed in [13603].
comment:5 by , 10 years ago
Cc: | added |
---|---|
Owner: | changed from | to
comment:6 by , 10 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
After [13603], attachment add
command adds an attachment with the original path name on Windows if the path is not a full path.
Trac [C:\usr\var\trac\1.1.3dev]> attachment add wiki:WikiStart .\contrib\trac-svn-post-commit-hook.cmd Trac [C:\usr\var\trac\1.1.3dev]> attachment add wiki:WikiStart C:\usr\src\trac\trunk\contrib\README Trac [C:\usr\var\trac\1.1.3dev]> attachment list wiki:WikiStart Name Size Author Date Description ---------------------------------------------------------------------------------------------- .\\contrib\\trac-svn-post-commit-hook.cmd 3.2 KB trac 2015-01-03 18:11:17 README 328 bytes trac 2015-01-03 18:18:08
-
trac/attachment.py
1060 1060 attachment = Attachment(self.env, realm, id) 1061 1061 attachment.author = author 1062 1062 attachment.description = description 1063 filename = _normalized_filename(path)1063 filename = os.path.basename(_normalized_filename(path)) 1064 1064 with open(path, 'rb') as f: 1065 1065 attachment.insert(filename, f, os.path.getsize(path)) 1066 1066
comment:7 by , 10 years ago
Thanks, I didn't test on Windows. Please go ahead and commit the change.
follow-up: 10 comment:9 by , 9 years ago
In [13603], I made _normalized_filename
a protected function. However, while working on AwesomeAttachmentPlugin I've considered that it would be useful if this function was public, and there seems little downside to the change. Is there any objection to the change?
I'm less certain, but perhaps the function would even be appropriate for trac.util
?
follow-up: 11 comment:10 by , 9 years ago
Replying to Ryan J Ollos:
In [13603], I made
_normalized_filename
a protected function. However, while working on AwesomeAttachmentPlugin I've considered that it would be useful if this function was public, and there seems little downside to the change. Is there any objection to the change?
I think such plugins need a utility method to add a new attachment with the filename normalization and checks of file size and permissions, not _normalize_filename
.
th:TracDragDropPlugin calls AttachmentModule.process_request()
using hack to add a attachment. See th:source:tracdragdropplugin/0.12/tracdragdrop/web_ui.py@14397:203-209,229-243#L224.
comment:11 by , 9 years ago
Replying to Jun Omae:
I think such plugins need a utility method to add a new attachment with the filename normalization and checks of file size and permissions, not
_normalize_filename
.
I had similar thoughts, but was concerned about adding a method that wouldn't have enough general utility. Maybe we can separate out the req
and redirect from _do_save
and make a public method. I'll take another look.
by , 9 years ago
Attachment: | awesomeattachments.patch added |
---|
comment:12 by , 9 years ago
I did some work in log:rjollos.git:attachment_module_refactoring. attachment:awesomeattachments.patch shows that the reduction in code size would be significant for that plugin.
I haven't looked closely at th:TracDragDropPlugin. Would the refactoring be useful for that case? Also, maybe the method name read_file
is not good. It could be named, file_from_fieldstorage
, or is there another suggestion?
As mentioned on the mailing list, the following behaviors are seen:
Even with the patch, the browser will have the first chance to modify the filename. So as far as I can tell, if we implement some behavior in
AttachmentModule._do_save
to replace control codes with whitespace, it will really only help in the case that there are some browsers that pass along the filename with the control-codes still present.The following case was also mentioned on the mailing list:
When trying to view the file through the browser we get: No handler matched request to /attachment/wiki/WikiStart/file1 .txt.
I'm more convinced that this is hardly worth worrying about, but might something like the following work well?: log:rjollos.git:t11395
I don't understand everything that is going on inside of
_normalized_filename
, but at least we can easily write unit tests for it, and it might be appropriate fortrac.util
.