Skip to content
This repository has been archived by the owner on Apr 3, 2022. It is now read-only.

Commit

Permalink
fixed bug with bing links from Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
wengh committed Apr 10, 2021
1 parent 385969d commit eff2528
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions source/common.d
Original file line number Diff line number Diff line change
Expand Up @@ -317,27 +317,26 @@ string[string] getQueryParams(const string uri) {
/// Return a tuple of the search term that was typed in (if any),
/// the URL that was typed (if any), and the URL that was selected from the search results panel (if any)
Tuple!(string, "searchTerm", string, "enteredUrl", string, "selectedUrl") getSearchInfo(const string uri) {
if (!uri.toLower().startsWith("microsoft-edge:"))
throw new Exception("Not a 'MICROSOFT-EDGE' URI: " ~ uri);
immutable string edgePrefix = "microsoft-edge:";
if (uri.toLower().startsWith(edgePrefix))
return getSearchInfo(uri[edgePrefix.length .. $]);

auto returnTuple = typeof(return)(tuple(null, null, null));
string[string] queryParams = getQueryParams(uri);

if (queryParams is null || "url" !in queryParams)
if (queryParams is null)
return returnTuple;

const string urlParam = queryParams["url"].decodeComponent();

if (urlParam.matchFirst(r"^https:\/\/.+\.bing.com")) {
queryParams = getQueryParams(urlParam);

if ("url" in queryParams && "q" in queryParams) {
returnTuple.searchTerm = queryParams["q"].decodeComponent();
returnTuple.selectedUrl = cast(string) Base64URL.decode(queryParams["url"]);
} else if ("q" in queryParams)
returnTuple.searchTerm = queryParams["q"].decodeComponent();
} else
returnTuple.enteredUrl = urlParam;
if ("url" in queryParams && "q" in queryParams) {
returnTuple.searchTerm = queryParams["q"].decodeComponent();
returnTuple.selectedUrl = cast(string) Base64URL.decode(queryParams["url"]);
} else if ("q" in queryParams) {
returnTuple.searchTerm = queryParams["q"].decodeComponent();
} else if ("url" in queryParams) {
returnTuple = getSearchInfo(queryParams["url"].decodeComponent());
} else {
returnTuple.enteredUrl = uri;
}

return returnTuple;
}
Expand Down

0 comments on commit eff2528

Please sign in to comment.