Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/isMagnetURI.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assertString from './util/assertString';

const magnetURIComponent = /(?:^magnet:\?|[^?&]&)xt(?:\.1)?=urn:(?:(?:aich|bitprint|btih|ed2k|ed2khash|kzhash|md5|sha1|tree:tiger):[a-z0-9]{32}(?:[a-z0-9]{8})?|btmh:1220[a-z0-9]{64})(?:$|&)/i;
const magnetURIComponent = /(?:^magnet:\?|[^?&]&)xt(?:\.1)?=urn:(?:(?:aich|bitprint|btih|ed2k|ed2khash|kzhash|md5|sha1|tree:tiger):[a-z0-9]{32}(?:[a-z0-9]{8})?|btmh:1220[a-f0-9]{64})(?:$|&)/i;

export default function isMagnetURI(url) {
assertString(url);
Expand Down
17 changes: 17 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12771,6 +12771,23 @@ describe('Validators', () => {
});


it('should require hexadecimal BitTorrent v2 magnet hashes', () => {
const hash = '0123456789abcdef'.repeat(4);
test({
validator: 'isMagnetURI',
valid: [
`magnet:?xt=urn:btmh:1220${hash}`,
`magnet:?xt=urn:btmh:1220${hash.toUpperCase()}`,
`magnet:?dn=example&xt.1=urn:btmh:1220${hash}&tr=udp://example.com`,
],
invalid: [
`magnet:?xt=urn:btmh:1220g${hash.slice(1)}`,
`magnet:?xt=urn:btmh:1220${hash.slice(0, -1)}Z`,
`magnet:?dn=example&xt.1=urn:btmh:1220${hash.slice(0, 32)}g${hash.slice(33)}&dn=test`,
],
});
});

it('should validate LatLong', () => {
test({
validator: 'isLatLong',
Expand Down
Loading