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

关于复制的图片连接编码问题 #731

Closed
g8up opened this issue Aug 23, 2021 · 9 comments
Closed

关于复制的图片连接编码问题 #731

g8up opened this issue Aug 23, 2021 · 9 comments
Labels

Comments

@g8up
Copy link

g8up commented Aug 23, 2021

我在开发自定义插件时发现,相册中,复制的图片连接和编辑弹框中的连接不一致了。
排查发现,复制的链接被 encodeURI():

const url = handleUrlEncode(item.url || item.imgUrl)

能否不修改这个链接?
我的情况:
预期的 "&Signature=zHx21zThzHKdNXJzFfpXFv0%2Befg%3D"
被转义成:'&Signature=zHx21zThzHKdNXJzFfpXFv0%252Befg%253D'
导致复制的图片链接失效

@Molunerfinn
Copy link
Owner

这里应该是个bug,因为最终落地的时候已经encode一次了,所以这里复制的时候不需要再encode了

@Molunerfinn
Copy link
Owner

正式版会解决

@g8up
Copy link
Author

g8up commented Mar 22, 2023

问下,这个 bug 在 2.4.0-beta.0 中修复了吗?
好像跟 #996 有点像。

@g8up g8up changed the title 关于图片连接编码问题 关于复制的图片连接编码问题 Mar 22, 2023
@Molunerfinn
Copy link
Owner

2.3.1应该就修复了

@g8up
Copy link
Author

g8up commented Mar 23, 2023

2.4.0-beta.0 中测试发现,复制和修改中的 URL 还是不一致。复制的地址有问题,导致正常无法访问对应图片。编辑框里的没问题。

export default (style: IPasteStyle, item: ImgInfo, customLink: string | undefined) => {
const url = handleUrlEncode(item.url || item.imgUrl)
const _customLink = customLink || '$url'
const tpl = {
markdown: `![](${url})`,
HTML: `<img src="${url}"/>`,
URL: url,
UBB: `[IMG]${url}[/IMG]`,
Custom: formatCustomLink(_customLink, item)
}
return tpl[style]
}

export const isUrlEncode = (url: string): boolean => {
url = url || ''
try {
return url !== decodeURI(url)
} catch (e) {
// if some error caught, try to let it go
return true
}
}
export const handleUrlEncode = (url: string): string => {
if (!isUrlEncode(url)) {
url = encodeURI(url)
}
return url
}

为啥复制的时候要 encode 一下?是不是缺了一步 decode?

@Molunerfinn
Copy link
Owner

6c6f847

之前删掉了来着,可能是迁移的时候写错了。我回头改一下吧

Molunerfinn added a commit that referenced this issue Mar 25, 2023
Molunerfinn added a commit that referenced this issue Apr 9, 2023
@g8up
Copy link
Author

g8up commented Jun 10, 2023

更新到 2.4.0-beta.1,还能复现这个问题。
url中的 %3D被转义成了%253D

@Molunerfinn
Copy link
Owner

更新到 2.4.0-beta.1,还能复现这个问题。

url中的 %3D被转义成了%253D

新增了个是否转义的配置项

@g8up
Copy link
Author

g8up commented Jun 11, 2023

关闭复制转义配置后,符合预期了。感谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants