mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-06 12:52:26 +00:00
Fix magnet query parsing for values containing '='
This commit is contained in:
1 parent
b2d1cd1383
commit
d10d65634d
2 files changed
+50
-1
No files matched your search
@@ -254,3 +254,50 @@ test("normalizeAndAugmentMagnet keeps unchanged xt/tr/ws/xs params singular", ()
|
||||
"Inbound xs hint should remain singular"
|
||||
);
|
||||
});
|
||||
|
||||
test("normalizeMagnetInput preserves parameter values containing additional equals signs", () => {
|
||||
const infoHash = "0123456789abcdef0123456789abcdef01234567";
|
||||
const rawMagnet =
|
||||
`magnet:?xt=urn:btih:${infoHash}` +
|
||||
"&ws=https://cdn.example.com/video.mp4%3FX-Amz-Signature=abc123==%26X-Amz-Credential=test%3Dvalue" +
|
||||
"&xs=https://cdn.example.com/video.torrent%3Ftoken=ZXlKaGJHY2lPaUpJVXpJMU5pSjkuZXlKcFpDST0=%26policy=a%3Db" +
|
||||
"&dn=Episode=01=Directors=Cut" +
|
||||
"&foo=bar=baz==";
|
||||
|
||||
const normalized = normalizeMagnetInput(rawMagnet);
|
||||
const valuesByKey = Object.fromEntries(
|
||||
normalized.params.map((param) => [param.lowerKey, param.value])
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
valuesByKey.ws,
|
||||
"https://cdn.example.com/video.mp4%3FX-Amz-Signature=abc123==%26X-Amz-Credential=test%3Dvalue",
|
||||
"ws should keep the full signed URL token"
|
||||
);
|
||||
assert.equal(
|
||||
valuesByKey.xs,
|
||||
"https://cdn.example.com/video.torrent%3Ftoken=ZXlKaGJHY2lPaUpJVXpJMU5pSjkuZXlKcFpDST0=%26policy=a%3Db",
|
||||
"xs should keep base64-like payloads and nested query params intact"
|
||||
);
|
||||
assert.equal(
|
||||
valuesByKey.dn,
|
||||
"Episode=01=Directors=Cut",
|
||||
"dn should preserve all '=' characters"
|
||||
);
|
||||
assert.equal(
|
||||
valuesByKey.foo,
|
||||
"bar=baz==",
|
||||
"Unknown params should preserve all '=' characters"
|
||||
);
|
||||
|
||||
const rebuilt = buildMagnetUri(
|
||||
normalized.normalizedScheme,
|
||||
normalized.params,
|
||||
normalized.fragment
|
||||
);
|
||||
assert.equal(
|
||||
rebuilt,
|
||||
rawMagnet,
|
||||
"buildMagnetUri should reproduce multi-equals values verbatim"
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user