🐛 Fix: url encode bug && copy-paste url encode bug

ISSUES CLOSED: #996
This commit is contained in:
PiEgg 2022-10-24 17:14:39 +08:00
parent 404d7667e0
commit 4de7a1d5f2
4 changed files with 9 additions and 8 deletions

View File

@ -48,7 +48,7 @@
"keycode": "^2.2.0", "keycode": "^2.2.0",
"lodash-id": "^0.14.0", "lodash-id": "^0.14.0",
"lowdb": "^1.0.0", "lowdb": "^1.0.0",
"picgo": "^1.5.0-alpha.10", "picgo": "^1.5.0-alpha.15",
"qrcode.vue": "^1.7.0", "qrcode.vue": "^1.7.0",
"shell-path": "2.1.0", "shell-path": "2.1.0",
"uuidv4": "^6.2.11", "uuidv4": "^6.2.11",

View File

@ -1,4 +1,5 @@
import { IPasteStyle } from '#/types/enum' import { IPasteStyle } from '#/types/enum'
import { handleUrlEncode } from '#/utils/common'
const formatCustomLink = (customLink: string, item: ImgInfo) => { const formatCustomLink = (customLink: string, item: ImgInfo) => {
const fileName = item.fileName!.replace(new RegExp(`\\${item.extname}$`), '') const fileName = item.fileName!.replace(new RegExp(`\\${item.extname}$`), '')
@ -18,7 +19,7 @@ const formatCustomLink = (customLink: string, item: ImgInfo) => {
} }
export default (style: IPasteStyle, item: ImgInfo, customLink: string | undefined) => { export default (style: IPasteStyle, item: ImgInfo, customLink: string | undefined) => {
const url = item.url || item.imgUrl const url = handleUrlEncode(item.url || item.imgUrl)
const _customLink = customLink || '$url' const _customLink = customLink || '$url'
const tpl = { const tpl = {
markdown: `![](${url})`, markdown: `![](${url})`,

View File

@ -2,7 +2,7 @@ export const isUrl = (url: string): boolean => (url.startsWith('http://') || url
export const isUrlEncode = (url: string): boolean => { export const isUrlEncode = (url: string): boolean => {
url = url || '' url = url || ''
try { try {
return url !== decodeURIComponent(url) return url !== decodeURI(url)
} catch (e) { } catch (e) {
// if some error caught, try to let it go // if some error caught, try to let it go
return true return true
@ -11,7 +11,7 @@ export const isUrlEncode = (url: string): boolean => {
export const handleUrlEncode = (url: string): string => { export const handleUrlEncode = (url: string): string => {
if (!isUrlEncode(url)) { if (!isUrlEncode(url)) {
url = encodeURIComponent(url) url = encodeURI(url)
} }
return url return url
} }

View File

@ -9919,10 +9919,10 @@ performance-now@^2.1.0:
resolved "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" resolved "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns= integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=
picgo@^1.5.0-alpha.10: picgo@^1.5.0-alpha.15:
version "1.5.0-alpha.10" version "1.5.0-alpha.15"
resolved "https://registry.npmjs.org/picgo/-/picgo-1.5.0-alpha.10.tgz#fd567ac60c831395d5f16b80cf59646cab492c9a" resolved "https://registry.npmjs.org/picgo/-/picgo-1.5.0-alpha.15.tgz#406c1cd48afc5c98f1d5084596e8bcecb637ad58"
integrity sha512-uFVFXxocbqXyc3lpGGIY2Sn55osXZWrTsNh9/CBSgJSqRVkp13nYnLMffZTp2+zzd/mDTpdqf/AUuEFI9dho+A== integrity sha512-+uU2gbFi/kc5qi0wrqk0hSFusUqEYKTay9hIHcQ13un+7xx5kwir99mwwKpNB+K8wHARntjurN9HCZEszgTKmQ==
dependencies: dependencies:
"@picgo/i18n" "^1.0.0" "@picgo/i18n" "^1.0.0"
"@picgo/store" "^2.0.2" "@picgo/store" "^2.0.2"