@@ -89,11 +89,11 @@ func queryWikipediaInternal(ctx context.Context, query string, completeArticle,
8989 span .AddField ("title" , query )
9090 log .Printf ("Looking up Wikipedia article: %q (complete: %t)\n " , query , completeArticle )
9191 qs := url .QueryEscape (query )
92- url := "https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles=" + qs + "&rvslots=main"
92+ u := "https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles=" + qs + "&rvslots=main"
9393 if ! completeArticle {
94- url += "&rvsection=0"
94+ u += "&rvsection=0"
9595 }
96- request , err := http .NewRequestWithContext (ctx , "GET" , url , nil )
96+ request , err := http .NewRequestWithContext (ctx , "GET" , u , nil )
9797 if err != nil {
9898 return "" , err
9999 }
@@ -115,7 +115,7 @@ func queryWikipediaInternal(ctx context.Context, query string, completeArticle,
115115 return "" , err
116116 }
117117 if ! strings .Contains (string (content ), "pageid=" ) {
118- if allowSearch {
118+ if ! allowSearch {
119119 return "" , errors .New ("no page exists with that name" )
120120 }
121121 // try searching for the page.
@@ -140,7 +140,7 @@ func searchWikipedia(ctx context.Context, query string) ([]string, error) {
140140 defer span .Send ()
141141 span .AddField ("query" , query )
142142 log .Printf ("Searching Wikipedia for %q\n " , query )
143- request , err := http .NewRequestWithContext (ctx , "GET" , "https://en.wikipedia.org/w/api.php?action=opensearch&limit=5&namespace=0&format=json&redirects=resolve&search=" + query , nil )
143+ request , err := http .NewRequestWithContext (ctx , "GET" , "https://en.wikipedia.org/w/api.php?action=opensearch&limit=5&namespace=0&format=json&redirects=resolve&search=" + url . QueryEscape ( query ) , nil )
144144 if err != nil {
145145 log .Printf ("Creating request failed: %v\n " , err )
146146 return nil , err
0 commit comments