@@ -23,6 +23,14 @@ describe('isRedirectURL', () => {
2323 const config = { ...baseConfig , ...additionals } ;
2424 config . URLPatterns = [ ...config . URLPatterns , ...URLPatterns ] ;
2525 config . HostNamePatterns = [ ...config . HostNamePatterns , ...HostNamePatterns ] ;
26+ if ( config . UseRegex ) {
27+ config . URLPatternsMatchers = { } ;
28+ config . HostNamePatternsMatchers = { } ;
29+ if ( config . UseRegex ) {
30+ redirector . _generateMatcher ( config . URLPatterns , config . URLPatternsMatchers ) ;
31+ redirector . _generateMatcher ( config . HostNamePatterns , config . HostNamePatternsMatchers ) ;
32+ }
33+ }
2634 return config ;
2735 }
2836 describe ( 'Empty redirect pattern' , ( ) => {
@@ -49,16 +57,53 @@ describe('isRedirectURL', () => {
4957 } ) ;
5058 } ) ;
5159 describe ( 'HostName patterns' , ( ) => {
52- it ( `Match redirect pattern` , ( ) => {
60+ it ( `Match redirect pattern without wildcard` , ( ) => {
61+ const url = 'http://www.example.com/' ;
62+ const conf = config ( [ ] , [ [ 'www.example.com' , 'firefox' ] ] )
63+ assert . equal ( redirector . isRedirectURL ( conf , url ) , true ) ;
64+ } ) ;
65+ it ( `Match redirect pattern with wildcard` , ( ) => {
5366 const url = 'http://www.example.com/' ;
5467 const conf = config ( [ ] , [ [ '*.example.com' , 'firefox' ] ] )
5568 assert . equal ( redirector . isRedirectURL ( conf , url ) , true ) ;
5669 } ) ;
57- it ( `Unmatch redirect pattern` , ( ) => {
70+ it ( `Match redirect pattern with regex: partial match` , ( ) => {
71+ const url = 'http://www.example.com/' ;
72+ const conf = config ( [ ] , [ [ 'www\.example\.com' , 'firefox' ] ] , { UseRegex : 1 } )
73+ console . log ( conf ) ;
74+ assert . equal ( redirector . isRedirectURL ( conf , url ) , true ) ;
75+ } ) ;
76+ it ( `Match redirect pattern with regex: exact match` , ( ) => {
77+ const url = 'http://www.example.com/' ;
78+ const conf = config ( [ ] , [ [ '^www\.example\.com$' , 'firefox' ] ] , { UseRegex : 1 } )
79+ console . log ( conf ) ;
80+ assert . equal ( redirector . isRedirectURL ( conf , url ) , true ) ;
81+ } ) ;
82+ it ( `Unmatch redirect pattern without wildcard` , ( ) => {
83+ const url = 'http://www.google.com/' ;
84+ const conf = config ( [ ] , [ [ 'www.example.com' , 'firefox' ] ] )
85+ assert . equal ( redirector . isRedirectURL ( conf , url ) , false ) ;
86+ } ) ;
87+ it ( `Unmatch redirect pattern extra scheme` , ( ) => {
88+ const url = 'http://www.example.com/' ;
89+ const conf = config ( [ ] , [ [ 'http://www.example.com' , 'firefox' ] ] )
90+ assert . equal ( redirector . isRedirectURL ( conf , url ) , false ) ;
91+ } ) ;
92+ it ( `Unmatch redirect pattern with wildcard` , ( ) => {
5893 const url = 'http://www.google.com/' ;
5994 const conf = config ( [ ] , [ [ '*.example.com' , 'firefox' ] ] )
6095 assert . equal ( redirector . isRedirectURL ( conf , url ) , false ) ;
6196 } ) ;
97+ it ( `Unmatch redirect pattern with regex` , ( ) => {
98+ const url = 'http://www.google.com/' ;
99+ const conf = config ( [ ] , [ [ 'www\.example\.com' , 'firefox' ] ] , { UseRegex : 1 } )
100+ assert . equal ( redirector . isRedirectURL ( conf , url ) , false ) ;
101+ } ) ;
102+ it ( `Unmatch redirect pattern extra scheme with regex` , ( ) => {
103+ const url = 'http://www.example.com/' ;
104+ const conf = config ( [ ] , [ [ 'http://www.example.com' , 'firefox' ] ] , { UseRegex : 1 } )
105+ assert . equal ( redirector . isRedirectURL ( conf , url ) , false ) ;
106+ } ) ;
62107 } ) ;
63108 } ) ;
64109 } ) ;
0 commit comments