mirror of
https://github.com/iptv-org/iptv
synced 2026-09-09 13:27:58 -04:00
fix: keep malformed URLs during normalization (#49870)
This commit is contained in:
+11
-2
@@ -39,9 +39,18 @@ export function isURI(string: string): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function normalizeURL(url: string): string {
|
export function normalizeURL(url: string): string {
|
||||||
const normalized = normalizeUrl(url, { stripWWW: false })
|
let normalized: string
|
||||||
|
try {
|
||||||
|
normalized = normalizeUrl(url, { stripWWW: false })
|
||||||
|
} catch {
|
||||||
|
return url.replace(/\s/g, '+')
|
||||||
|
}
|
||||||
|
|
||||||
return decodeURIComponent(normalized).replace(/\s/g, '+').toString()
|
try {
|
||||||
|
return decodeURIComponent(normalized).replace(/\s/g, '+')
|
||||||
|
} catch {
|
||||||
|
return normalized.replace(/\s/g, '+')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function truncate(string: string, limit: number = 100) {
|
export function truncate(string: string, limit: number = 100) {
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#EXTM3U
|
||||||
|
#EXTINF:-1 tvg-id="",Example (720p)
|
||||||
|
http://example.com/a%ZZ
|
||||||
@@ -30,6 +30,19 @@ describe('playlist:format', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('keeps links with malformed percent escapes', () => {
|
||||||
|
fs.emptyDirSync('tests/__data__/output')
|
||||||
|
fs.copySync('tests/__data__/input/playlist_normalize', 'tests/__data__/output/streams')
|
||||||
|
|
||||||
|
const cmd =
|
||||||
|
'cross-env STREAMS_DIR=tests/__data__/output/streams DATA_DIR=tests/__data__/input/data npm run playlist:format'
|
||||||
|
execSync(cmd, { encoding: 'utf8' })
|
||||||
|
|
||||||
|
expect(content('tests/__data__/output/streams/bad_encoding.m3u')).toContain(
|
||||||
|
'http://example.com/a%ZZ'
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
function content(filepath: string) {
|
function content(filepath: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user