fix: keep encoded query delimiters when playlist:format normalizes links

normalize-url sorts the query parameters by default and then runs decodeURIComponent on the whole query, so %26, %3D, %3F and %2B come back as &, =, ? and +. A link that passes another URL as a parameter loses part of it to the outer query, and %2B turns into a space. The order of the parameters is now left as is.
This commit is contained in:
leoca
2026-11-14 03:37:50 +00:00
parent 0f5728f287
commit d7c1a01cf6
3 changed files with 6 additions and 1 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ export function isURI(string: string): boolean {
export function normalizeURL(url: string): string {
let normalized: string
try {
normalized = normalizeUrl(url, { stripWWW: false })
normalized = normalizeUrl(url, { stripWWW: false, sortQueryParameters: false })
} catch {
return url.replace(/\s/g, '+')
}
@@ -5,3 +5,5 @@ http://example.com/TVP%20Wilno%20HD/index.m3u8
http://example.com/a%2Fb/index.m3u8
#EXTINF:-1 tvg-id="",Example Query Hash (720p)
http://example.com/index.m3u8?id=1%232
#EXTINF:-1 tvg-id="",Example Query Nested URL (720p)
http://example.com/index.m3u8?name=TV%2B&url=http%3A%2F%2Fexample.org%2Fa.m3u8%3Fk%3D1%26exp%3D2
+3
View File
@@ -67,6 +67,9 @@ describe('playlist:format', () => {
expect(output).toContain('http://example.com/TVP%20Wilno%20HD/index.m3u8')
expect(output).toContain('http://example.com/a%2Fb/index.m3u8')
expect(output).toContain('http://example.com/index.m3u8?id=1%232')
expect(output).toContain(
'http://example.com/index.m3u8?name=TV%2B&url=http%3A%2F%2Fexample.org%2Fa.m3u8%3Fk%3D1%26exp%3D2'
)
})
})