@@ -164,24 +164,9 @@ static string RewriteMsEdgeUriSchema(string uri)
164164 Regex rgx = new Regex ( msedge_protocol_pattern ) ;
165165 string new_uri = rgx . Replace ( uri , string . Empty ) ;
166166
167- if ( engine == "Google" )
168- {
169- int index = new_uri . IndexOf ( "&" ) ;
170- if ( index > 0 )
171- new_uri = new_uri . Substring ( 0 , index ) ;
172- new_uri = new_uri . Replace ( "bing.com/search?q=" , "google.com/search?q=" ) ;
173- }
174- else if ( engine == "DuckDuckGo" )
175- {
176- int index = new_uri . IndexOf ( "&" ) ;
177- if ( index > 0 )
178- new_uri = new_uri . Substring ( 0 , index ) ;
179- new_uri = new_uri . Replace ( "bing.com/search?q=" , "duckduckgo.com/?q=" ) ;
180- }
181-
182167 if ( IsHttpUri ( new_uri ) )
183168 {
184- return new_uri ;
169+ return replaceSearchEngine ( new_uri , engine ) ;
185170 }
186171
187172 // May be new-style Cortana URI - try and split out
@@ -191,12 +176,29 @@ static string RewriteMsEdgeUriSchema(string uri)
191176 if ( IsHttpUri ( cortanaUri ) )
192177 {
193178 // Correctly form the new URI before returning
194- return cortanaUri ;
179+ return replaceSearchEngine ( cortanaUri , engine ) ;
195180 }
196181 }
197182
198183 // defer fallback to web browser
199- return "http://" + new_uri ;
184+ return "http://" + replaceSearchEngine ( new_uri , engine ) ;
185+ }
186+
187+ static string replaceSearchEngine ( string new_uri , string engine )
188+ {
189+ int index = new_uri . IndexOf ( "&" ) ;
190+ if ( index > 0 ) new_uri = new_uri . Substring ( 0 , index ) ;
191+
192+ if ( engine == "Google" )
193+ {
194+ return new_uri . Replace ( "bing.com/search?q=" , "google.com/search?q=" ) ;
195+ }
196+ else if ( engine == "DuckDuckGo" )
197+ {
198+ return new_uri . Replace ( "bing.com/search?q=" , "duckduckgo.com/?q=" ) ;
199+ }
200+
201+ return new_uri ;
200202 }
201203
202204 static void OpenUri ( string uri )
0 commit comments