From 6c986a5180134c49b760843237d6e99a31dd61e3 Mon Sep 17 00:00:00 2001 From: fan wu <336798967+FanWu-ai@users.noreply.github.com> Date: Sun, 11 Oct 2026 11:18:05 -0700 Subject: [PATCH] fix(isMagnetURI): restore case-insensitive scheme matching Restore the scheme case-insensitivity lost by the prefix guard in #1992. Add v1/v2, parameter-order and invalid-prefix regression cases. --- src/lib/isMagnetURI.js | 2 +- test/validators.test.js | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/lib/isMagnetURI.js b/src/lib/isMagnetURI.js index e00ee3c32..745a561d2 100644 --- a/src/lib/isMagnetURI.js +++ b/src/lib/isMagnetURI.js @@ -5,7 +5,7 @@ const magnetURIComponent = /(?:^magnet:\?|[^?&]&)xt(?:\.1)?=urn:(?:(?:aich|bitpr export default function isMagnetURI(url) { assertString(url); - if (url.indexOf('magnet:?') !== 0) { + if (!/^magnet:\?/i.test(url)) { return false; } diff --git a/test/validators.test.js b/test/validators.test.js index 98d2a12ff..8762b3601 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -12771,6 +12771,32 @@ describe('Validators', () => { }); + it('should validate magnet URI schemes case-insensitively', () => { + const btih = '0123456789012345678901234567890123456789'; + const btmh = `1220${'a'.repeat(64)}`; + test({ + validator: 'isMagnetURI', + valid: [ + `MAGNET:?xt=urn:btih:${btih}`, + `MaGnEt:?xt=urn:btih:${btih}`, + `MAGNET:?dn=example&xt=urn:btih:${btih}`, + `MaGnEt:?dn=example&xt=urn:btih:${btih}`, + `MAGNET:?xt=urn:btmh:${btmh}`, + `MaGnEt:?dn=example&xt=urn:btmh:${btmh}`, + ], + invalid: [ + ` MAGNET:?xt=urn:btih:${btih}`, + `prefixMAGNET:?xt=urn:btih:${btih}`, + `MAGNETA:?xt=urn:btih:${btih}`, + `MAGNET::?xt=urn:btih:${btih}`, + `MAGNET:xt=urn:btih:${btih}`, + 'MAGNET:?dn=example', + 'MAGNET:?xt=urn:btih:1234', + ], + }); + }); + + it('should validate LatLong', () => { test({ validator: 'isLatLong',