Skip to content

Commit fabf0da

Browse files
committed
fix: MagnetLink equality is not sensitive to query param order
1 parent 86237c0 commit fabf0da

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
- `MagnetFile` sorts and deduplicates the trackers provided in the magnet URL;
2323
`MagnetFile::trackers` returns them in an order, which is not specified
2424

25+
### Fixed
26+
27+
- `MagnetLink` equality is no longer affected by the exact representation of the
28+
magnet URL; if the name, hash, and (sorted/deduped) trackers are equal, then
29+
two magnets are considered equal
30+
2531
## Version 0.4.0 (2025-11-10)
2632

2733
This release is focused on stricter parsing of torrents and magnets, and

src/magnet.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,14 @@ impl std::fmt::Display for MagnetLink {
338338

339339
impl PartialEq for MagnetLink {
340340
fn eq(&self, other: &Self) -> bool {
341-
self.query == other.query
341+
// Here we may have different ordering of the URL params so we check the
342+
// values. This is more expensive but more correct.
343+
//
344+
// In the future, we may optimize this by reproducing a normalized query.
345+
self.name == other.name
346+
&& self.hash == other.hash
347+
// Trackers have been sorted in the constructor
348+
&& self.trackers == other.trackers
342349
}
343350
}
344351

0 commit comments

Comments
 (0)