Skip to content

Commit

Permalink
🐛 Fix: url encode bug && copy-paste url encode bug
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #996
  • Loading branch information
Molunerfinn committed Oct 24, 2022
1 parent 404d766 commit 4de7a1d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"keycode": "^2.2.0",
"lodash-id": "^0.14.0",
"lowdb": "^1.0.0",
"picgo": "^1.5.0-alpha.10",
"picgo": "^1.5.0-alpha.15",
"qrcode.vue": "^1.7.0",
"shell-path": "2.1.0",
"uuidv4": "^6.2.11",
Expand Down
3 changes: 2 additions & 1 deletion src/main/utils/pasteTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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 @@ -18,7 +19,7 @@ const formatCustomLink = (customLink: string, item: ImgInfo) => {
}

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 tpl = {
markdown: `![](${url})`,
Expand Down
4 changes: 2 additions & 2 deletions src/universal/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const isUrl = (url: string): boolean => (url.startsWith('http://') || url
export const isUrlEncode = (url: string): boolean => {
url = url || ''
try {
return url !== decodeURIComponent(url)
return url !== decodeURI(url)
} catch (e) {
// if some error caught, try to let it go
return true
Expand All @@ -11,7 +11,7 @@ export const isUrlEncode = (url: string): boolean => {

export const handleUrlEncode = (url: string): string => {
if (!isUrlEncode(url)) {
url = encodeURIComponent(url)
url = encodeURI(url)
}
return url
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9919,10 +9919,10 @@ performance-now@^2.1.0:
resolved "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=

picgo@^1.5.0-alpha.10:
version "1.5.0-alpha.10"
resolved "https://registry.npmjs.org/picgo/-/picgo-1.5.0-alpha.10.tgz#fd567ac60c831395d5f16b80cf59646cab492c9a"
integrity sha512-uFVFXxocbqXyc3lpGGIY2Sn55osXZWrTsNh9/CBSgJSqRVkp13nYnLMffZTp2+zzd/mDTpdqf/AUuEFI9dho+A==
picgo@^1.5.0-alpha.15:
version "1.5.0-alpha.15"
resolved "https://registry.npmjs.org/picgo/-/picgo-1.5.0-alpha.15.tgz#406c1cd48afc5c98f1d5084596e8bcecb637ad58"
integrity sha512-+uU2gbFi/kc5qi0wrqk0hSFusUqEYKTay9hIHcQ13un+7xx5kwir99mwwKpNB+K8wHARntjurN9HCZEszgTKmQ==
dependencies:
"@picgo/i18n" "^1.0.0"
"@picgo/store" "^2.0.2"
Expand Down

0 comments on commit 4de7a1d

Please sign in to comment.