File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change 11import assertString from './util/assertString' ;
22
3- const magnetURI = / ^ m a g n e t : \? x t (?: \. 1 ) ? = u r n : (?: a i c h | b i t p r i n t | b t i h | e d 2 k | e d 2 k h a s h | k z h a s h | m d 5 | s h a 1 | t r e e : t i g e r ) : [ a - z 0 - 9 ] { 32 } (?: [ a - z 0 - 9 ] { 8 } ) ? ( $ | & ) / i;
3+ const magnetURIComponent = / (?: ^ m a g n e t : \? | [ ^ ? & ] & ) x t (?: \. 1 ) ? = u r n : (?: (?: a i c h | b i t p r i n t | b t i h | e d 2 k | e d 2 k h a s h | k z h a s h | m d 5 | s h a 1 | t r e e : t i g e r ) : [ a - z 0 - 9 ] { 32 } (?: [ a - z 0 - 9 ] { 8 } ) ? | b t m h : 1 2 2 0 [ a - z 0 - 9 ] { 64 } ) (?: $ | & ) / i;
44
55export default function isMagnetURI ( url ) {
66 assertString ( url ) ;
7- return magnetURI . test ( url . trim ( ) ) ;
7+
8+ if ( url . indexOf ( 'magnet:?' ) !== 0 ) {
9+ return false ;
10+ }
11+
12+ return magnetURIComponent . test ( url ) ;
813}
Original file line number Diff line number Diff line change @@ -10256,6 +10256,8 @@ describe('Validators', () => {
1025610256 'magnet:?xt=urn:md5:ABCDEFGHIJKLMNOPQRSTUVWXYZ123456' ,
1025710257 'magnet:?xt=urn:tree:tiger:ABCDEFGHIJKLMNOPQRSTUVWXYZ123456' ,
1025810258 'magnet:?xt=urn:ed2k:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234' ,
10259+ 'magnet:?tr=udp://helloworld:1337/announce&xt=urn:btih:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234' ,
10260+ 'magnet:?xt=urn:btmh:1220caf1e1c30e81cb361b9ee167c4aa64228a7fa4fa9f6105232b28ad099f3a302e' ,
1025910261 ] ,
1026010262 invalid : [
1026110263 ':?xt=urn:btih:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234' ,
@@ -10268,6 +10270,8 @@ describe('Validators', () => {
1026810270 'magnet:?xt:urn:nonexisting:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234' ,
1026910271 'magnet:?xt.2=urn:btih:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234' ,
1027010272 'magnet:?xt=urn:ed2k:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567890123456789ABCD' ,
10273+ 'magnet:?xt=urn:btmh:1120caf1e1c30e81cb361b9ee167c4aa64228a7fa4fa9f6105232b28ad099f3a302e' ,
10274+ 'magnet:?ttxt=urn:btmh:1220caf1e1c30e81cb361b9ee167c4aa64228a7fa4fa9f6105232b28ad099f3a302e' ,
1027110275 ] ,
1027210276 } ) ;
1027310277 /* eslint-enable max-len */
You can’t perform that action at this time.
0 commit comments