Skip to content

Commit 1a45a44

Browse files
fix: use a safer encoding method
1 parent 6a24d62 commit 1a45a44

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/pages/library/components/game-entry.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client'
22
import clsx from 'clsx'
33
import { Link } from 'waku/router/client'
4+
import { encodeRFC3986URIComponent } from '@/utils/misc.ts'
45
import { getRomTitle } from '@/utils/rom.ts'
56
import { useRomCover } from '../hooks/use-rom-cover.ts'
67

@@ -13,7 +14,7 @@ export function GameEntry({ rom, width }) {
1314
<Link
1415
className='block'
1516
style={{ width: width || 'auto' }}
16-
to={`/library/platform/${encodeURIComponent(rom.platform)}/rom/${encodeURIComponent(rom.file_name)}`}
17+
to={`/library/platform/${encodeRFC3986URIComponent(rom.platform)}/rom/${encodeRFC3986URIComponent(rom.file_name)}`}
1718
unstable_pending={
1819
<div className='z-1 absolute inset-0'>
1920
<div className='grid h-4/5 w-full place-items-center'>

src/utils/cdn.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { encodeRFC3986URIComponent } from './misc.ts'
2+
13
const repositoryVersions = {
24
'batocera-linux/batocera-themes': 'cc0de2f',
35
'HerbFargus/es-theme-tronkyfran': 'a270311',
@@ -15,10 +17,6 @@ const repositoryVersions = {
1517
'RetroPie/es-theme-carbon': 'b09973e',
1618
} as const
1719

18-
function encodeRFC3986URIComponent(str: string) {
19-
return encodeURIComponent(str).replaceAll(/[!'()*]/g, (c) => `%${c.codePointAt(0)?.toString(16).toUpperCase()}`)
20-
}
21-
2220
export function getCDNUrl(repo: keyof typeof repositoryVersions, filePpath: string) {
2321
const [ghUser, ghRepoName] = repo.split('/')
2422
const version = repositoryVersions[repo]

src/utils/misc.ts

+4
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ export function humanizeDate(date: Date) {
2525
}
2626
return lightFormat(date, 'yyyy-MM-dd HH:mm')
2727
}
28+
29+
export function encodeRFC3986URIComponent(str: string) {
30+
return encodeURIComponent(str).replaceAll(/[!'()*]/g, (c) => `%${c.codePointAt(0)?.toString(16).toUpperCase()}`)
31+
}

0 commit comments

Comments
 (0)