@@ -36,17 +36,84 @@ describe('isRedirectURL', () => {
3636 assert . equal ( redirector . isRedirectURL ( config ( [ ] , [ ] , { DefaultBrowser : defaultBrowser } ) , url ) , true ) ;
3737 } ) ;
3838 } ) ;
39+ it ( `Match redirect pattern with regex: partial match` , ( ) => {
40+ const url = 'http://www.example.com/' ;
41+ const conf = config ( [ [ 'http://www\.example\.com/' , 'firefox' ] ] , [ ] , { UseRegex : 1 } )
42+ assert . equal ( redirector . isRedirectURL ( conf , url ) , true ) ;
43+ } ) ;
44+ it ( `Match redirect pattern with regex: exact match` , ( ) => {
45+ const url = 'http://www.example.com/' ;
46+ const conf = config ( [ [ '^http://www\.example\.com/$' , 'firefox' ] ] , [ ] , { UseRegex : 1 } )
47+ assert . equal ( redirector . isRedirectURL ( conf , url ) , true ) ;
48+ } ) ;
3949 describe ( 'URL patterns' , ( ) => {
40- it ( `Match redirect pattern` , ( ) => {
50+ it ( `Match redirect pattern with wild card ` , ( ) => {
4151 const url = 'http://www.example.com/' ;
4252 const conf = config ( [ [ 'http*://*.example.com/*' , 'firefox' ] ] )
4353 assert . equal ( redirector . isRedirectURL ( conf , url ) , true ) ;
4454 } ) ;
45- it ( `Unmatch redirect pattern` , ( ) => {
55+ it ( `Match first pattern: redirection (matches firefox)` , ( ) => {
56+ const url = 'http://www.example.com/' ;
57+ const conf = config (
58+ [
59+ [ 'not-match' , browser ] ,
60+ [ 'http*://*.example.com/*' , 'firefox' ] ,
61+ [ 'http*://*.example.com/*' , browser ]
62+ ] )
63+ assert . equal ( redirector . isRedirectURL ( conf , url ) , true ) ;
64+ } ) ;
65+ it ( `Match first pattern: non redirection (matches myself)` , ( ) => {
66+ const url = 'http://www.example.com/' ;
67+ const conf = config (
68+ [
69+ [ 'not-match' , browser ] ,
70+ [ 'http*://*.example.com/*' , browser ] ,
71+ [ 'http*://*.example.com/*' , 'firefox' ]
72+ ] )
73+ assert . equal ( redirector . isRedirectURL ( conf , url ) , false ) ;
74+ } ) ;
75+ it ( `Match first pattern with regex: redirection (matches firefox)` , ( ) => {
76+ // On 2.2.0 or before, patterns were grouped by browser, so they were matched in
77+ // the order in which the browsers appeared, rather than in top-down order of the patterns.
78+ // On the versions later than 2.2.0, the patterns were matched in the order in top-down order.
79+ const url = 'http://www.example.com/' ;
80+ const conf = config (
81+ [
82+ // We need this to make the "browser" the first appeared browser.
83+ [ 'not-match' , browser ] ,
84+ [ 'http://www\.example\.com/.*' , 'firefox' ] ,
85+ [ 'http://www\.example\.com/.*' , browser ]
86+ ] ,
87+ [ ] ,
88+ { UseRegex : 1 } )
89+ assert . equal ( redirector . isRedirectURL ( conf , url ) , true ) ;
90+ } ) ;
91+ it ( `Match first pattern with regex: non redirection (matches myself)` , ( ) => {
92+ // On 2.2.0 or before, patterns were grouped by browser, so they were matched in
93+ // the order in which the browsers appeared, rather than in top-down order of the patterns.
94+ // On the versions later than 2.2.0, the patterns were matched in the order in top-down order.
95+ const url = 'http://www.example.com/' ;
96+ const conf = config (
97+ [
98+ // We need this to make the "browser" the first appeared browser.
99+ [ 'not-match' , browser ] ,
100+ [ 'http://www\.example\.com/.*' , browser ] ,
101+ [ 'http://www\.example\.com/.*' , 'firefox' ]
102+ ] ,
103+ [ ] ,
104+ { UseRegex : 1 } )
105+ assert . equal ( redirector . isRedirectURL ( conf , url ) , false ) ;
106+ } ) ;
107+ it ( `Unmatch redirect pattern with wild card` , ( ) => {
46108 const url = 'http://www.google.com/' ;
47109 const conf = config ( [ [ 'http*://*.example.com/*' , 'firefox' ] ] )
48110 assert . equal ( redirector . isRedirectURL ( conf , url ) , false ) ;
49111 } ) ;
112+ it ( `Unmatch redirect pattern with regex` , ( ) => {
113+ const url = 'http://www.google.com/' ;
114+ const conf = config ( [ [ 'http://www\.example\.com/' , 'firefox' ] ] , [ ] , { UseRegex : 1 } )
115+ assert . equal ( redirector . isRedirectURL ( conf , url ) , false ) ;
116+ } ) ;
50117 } ) ;
51118 describe ( 'HostName patterns' , ( ) => {
52119 it ( `Match redirect pattern without wildcard` , ( ) => {
0 commit comments