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 1
1
import assertString from './util/assertString' ;
2
2
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;
4
4
5
5
export default function isMagnetURI ( url ) {
6
6
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 ) ;
8
13
}
Original file line number Diff line number Diff line change @@ -10256,6 +10256,8 @@ describe('Validators', () => {
10256
10256
'magnet:?xt=urn:md5:ABCDEFGHIJKLMNOPQRSTUVWXYZ123456' ,
10257
10257
'magnet:?xt=urn:tree:tiger:ABCDEFGHIJKLMNOPQRSTUVWXYZ123456' ,
10258
10258
'magnet:?xt=urn:ed2k:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234' ,
10259
+ 'magnet:?tr=udp://helloworld:1337/announce&xt=urn:btih:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234' ,
10260
+ 'magnet:?xt=urn:btmh:1220caf1e1c30e81cb361b9ee167c4aa64228a7fa4fa9f6105232b28ad099f3a302e' ,
10259
10261
] ,
10260
10262
invalid : [
10261
10263
':?xt=urn:btih:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234' ,
@@ -10268,6 +10270,8 @@ describe('Validators', () => {
10268
10270
'magnet:?xt:urn:nonexisting:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234' ,
10269
10271
'magnet:?xt.2=urn:btih:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234' ,
10270
10272
'magnet:?xt=urn:ed2k:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567890123456789ABCD' ,
10273
+ 'magnet:?xt=urn:btmh:1120caf1e1c30e81cb361b9ee167c4aa64228a7fa4fa9f6105232b28ad099f3a302e' ,
10274
+ 'magnet:?ttxt=urn:btmh:1220caf1e1c30e81cb361b9ee167c4aa64228a7fa4fa9f6105232b28ad099f3a302e' ,
10271
10275
] ,
10272
10276
} ) ;
10273
10277
/* eslint-enable max-len */
You can’t perform that action at this time.
0 commit comments