# PNG 和 PDF 上传文件名命名规范不一致

**URL:** <https://meta.discourse.org/t/inconsistent-png-and-pdf-upload-filenaming-conventions/135130>\
**Category:** Bug\
**Created:** [2019年十二月5日 05:51 UTC](https://meta.discourse.org/t/inconsistent-png-and-pdf-upload-filenaming-conventions/135130 "2019-12-05T05:51:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![robbie.morrison](https://avatars.discourse-cdn.com/v4/letter/r/c5a1d2/32.png) [@robbie.morrison](https://meta.discourse.org/u/robbie.morrison)\
**Post date:** [2019年十二月5日 05:51 UTC](https://meta.discourse.org/t/inconsistent-png-and-pdf-upload-filenaming-conventions/135130/1 "2019-12-05T05:51:33Z")

</div>

你好，开发者们

我最近使用 Discourse 2.4.0.beta7 及当前版本上传了两个内容完全相同的文件，格式分别为 PNG 和 PDF（已上传至 [openmod 论坛](https://forum.openmod-initiative.org)）。Discourse 会自动解析并将原始文件名记录在 Markdown 中，具体如下：

| 上传的文件名 | 显示的文件名 | 备注 |
| --- | --- | --- |
| bridge-2-a5-flier.04.png | 04 | 标注 1 |
| bridge-2-a5-flier.04.pdf | bridge-2-a5-flier.04.pdf | 标注 2 |

下方是一张截图，已用“1”和“2”标注以说明其工作原理：

 ![screenshot](https://global.discourse-cdn.com/meta/original/3X/8/f/8fe5a020da8afa82a4863f9475424a2abf7e51d8.png)

在我看来，PNG 文件的情况应该记录原始文件名，或者至少像这样记录完整的文件主体部分：`basename "bridge-2-a5-flier.04.png" ".png"`。

我查找了类似的错误报告，但只找到了关于匿名化名称字符串生成的相关讨论。

一如既往地感谢你们提供如此优秀的软件。R

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2019年十二月5日 08:08 UTC](https://meta.discourse.org/t/inconsistent-png-and-pdf-upload-filenaming-conventions/135130/2 "2019-12-05T08:08:57Z")

</div>

同意，根据文件名中的句号来看，这看起来像是一个错误。

---

<div class="post-metadata">

**Author:** ![martin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/martin/32/491371_2.png) [@martin](https://meta.discourse.org/u/martin)\
**Post date:** [2019年十二月5日 22:29 UTC](https://meta.discourse.org/t/inconsistent-png-and-pdf-upload-filenaming-conventions/135130/4 "2019-12-05T22:29:24Z")

</div>

我已经查看过了，这确实是一个由文件名中包含 `.` 引起的 bug。Composer 试图仅移除文件扩展名，结果导致 Markdown 中出现了 `bridge-2-a5-flier.04|WIDTHxHEIGHT`。但实际上它只是在 `.` 处分割文件名，并取扩展名之前的第一部分，这显然是不正确的。

据我所知，这个 bug 已经存在两年了，感谢您如此 🦅-eyed 并发现了它！我今天会提交修复。

---

<div class="post-metadata">

**Author:** ![martin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/martin/32/491371_2.png) [@martin](https://meta.discourse.org/u/martin)\
**Post date:** [2019年十二月6日 00:58 UTC](https://meta.discourse.org/t/inconsistent-png-and-pdf-upload-filenaming-conventions/135130/5 "2019-12-06T00:58:56Z")

</div>

已修复，详见 [FIX: Image file names with dots were showing incorrectly in composer markdown by martin-brennan · Pull Request #8465 · discourse/discourse · GitHub](https://github.com/discourse/discourse/pull/8465)

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2019年十二月6日 07:00 UTC](https://meta.discourse.org/t/inconsistent-png-and-pdf-upload-filenaming-conventions/135130/6 "2019-12-06T07:00:07Z")

</div>

此主题已在 5 小时后自动关闭。不再允许新回复。
