Don't crash if URI can't be parsed (#11788)

This commit is contained in:
Mykhailo Pylyp 2021-06-18 13:01:40 +03:00 committed by GitHub
parent 70b9c0f879
commit 735accc1a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.Search.Interop; using Microsoft.Search.Interop;
using Wox.Plugin.Logger;
namespace Microsoft.Plugin.Indexer.SearchHelper namespace Microsoft.Plugin.Indexer.SearchHelper
{ {
@ -49,7 +50,12 @@ namespace Microsoft.Plugin.Indexer.SearchHelper
// # is URI syntax for the fragment component, need to be encoded so LocalPath returns complete path // # is URI syntax for the fragment component, need to be encoded so LocalPath returns complete path
// Using OrdinalIgnoreCase since this is internal and used with symbols // Using OrdinalIgnoreCase since this is internal and used with symbols
var string_path = ((string)oleDBResult.FieldData[0]).Replace("#", "%23", StringComparison.OrdinalIgnoreCase); var string_path = ((string)oleDBResult.FieldData[0]).Replace("#", "%23", StringComparison.OrdinalIgnoreCase);
var uri_path = new Uri(string_path);
if (!Uri.TryCreate(string_path, UriKind.RelativeOrAbsolute, out Uri uri_path))
{
Log.Warn($"Failed to parse URI '${string_path}'", typeof(WindowsSearchAPI));
continue;
}
var result = new SearchResult var result = new SearchResult
{ {