Skip to content

Commit

Permalink
🐛 Fix: fix copy link encoding bug
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #731
  • Loading branch information
Molunerfinn committed Mar 25, 2023
1 parent 455cb49 commit 34657ae
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/main/utils/pasteTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IPasteStyle } from '#/types/enum'
import { handleUrlEncode } from '#/utils/common'

const formatCustomLink = (customLink: string, item: ImgInfo) => {
const fileName = item.fileName!.replace(new RegExp(`\\${item.extname}$`), '')
Expand All @@ -21,7 +20,7 @@ const formatCustomLink = (customLink: string, item: ImgInfo) => {
}

export default (style: IPasteStyle, item: ImgInfo, customLink: string | undefined) => {
const url = handleUrlEncode(item.url || item.imgUrl)
const url = item.url || item.imgUrl
const _customLink = customLink || '$url'
const tpl = {
markdown: `![](${url})`,
Expand Down

5 comments on commit 34657ae

@Kuingsmile
Copy link

@Kuingsmile Kuingsmile commented on 34657ae Mar 25, 2023

Choose a reason for hiding this comment

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

这里应该不能去掉handleUrlEncode, 否则当文件名含有特殊字符时复制的链接还是不能访问的。

例如我上传了一张名为%eva 副本.jpg的图片,去掉handleUrlEncode之后复制到的链接是
[http://pichoro.test.upcdn.net/%eva 11.jpg](http://pichoro.test.upcdn.net/%eva 11.jpg),这时候访问会报错。

我认为需要修改的是src/universal/utils/common.ts里的isUrlEncode函数,decodeURI在解码报错的时候,本身就是说明uri未经编码,所以不能直接返回true,而应该返回false.

catch里的return修改为false后,再上传拿到的链接是
http://pichoro.test.upcdn.net/%25eva%2011.jpg
,这时候访问和用在markdown里都是正常的了。

image

image

@Molunerfinn
Copy link
Owner Author

Choose a reason for hiding this comment

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

我想了下,去不去掉都会有问题。不去掉的话,#731 的问题会依然存在,因为多了一层 encode 。

这里需要多加一个配置来处理复制的行为。

return false 我觉得是可以改的。

@Kuingsmile
Copy link

Choose a reason for hiding this comment

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

#731 的问题我木有太理解,按理说相册编辑弹出框里的链接本身是未encode过的吧,这时候复制加一层encode应该是没问题的,除非手动把相册的链接改成encode过的了

@Molunerfinn
Copy link
Owner Author

Choose a reason for hiding this comment

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

用户自行开发的插件,URL里的内容是无法控制的

@Kuingsmile
Copy link

Choose a reason for hiding this comment

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

用户自行开发的插件,URL里的内容是无法控制的

这倒是。。这样看加个配置是最灵活的。。

Please sign in to comment.