Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private buildUrl(query: string) {
// See if they have started with a web scheme
if (/^https?:\/\/\w+/.test(query)) {
return query;
}
// See if they have ended with a valid TLD
if (tlds.some(tld => query.endsWith(`.${tld}`))) {
return `https://${query}`;
}
// Probably searching then
const searchEngine =
engines.find(engine => engine.key === this.props.data!.searchEngine) ||
engines[0];
return searchEngine.search_url.replace('{searchTerms}', query);
}
export function buildUrl(query: string, engineUrl: string) {
// See if they have started with a web scheme
if (/^https?:\/\/\w+/.test(query)) {
return query;
}
// See if they have ended with a valid TLD
if (tlds.some(tld => query.endsWith(`.${tld}`))) {
return `https://${query}`;
}
// Probably searching then
return engineUrl.replace('{searchTerms}', encodeURIComponent(query));
}