Skip to content

Commit caa67ec

Browse files
committed
fix: Resolve CA1056 code analysis violations in web search connectors
- Changed Url property from string? to Uri? in TavilyWebPage - Changed Url property from string? to Uri? in BraveWebPage - Updated constructors to accept Uri? parameters - Added null-safe string-to-Uri conversions in factory methods - Fixed image URL handling in TavilyTextSearch Resolves all 31 CA1056 violations (URI properties should not be strings).
1 parent f78aa7e commit caa67ec

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

dotnet/src/Plugins/Plugins.Web/Brave/BraveWebPage.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public sealed class BraveWebPage
1818
/// <summary>
1919
/// Gets or sets the URL of the web page.
2020
/// </summary>
21-
public string? Url { get; set; }
21+
public Uri? Url { get; set; }
2222

2323
/// <summary>
2424
/// Gets or sets the description of the web page.
@@ -118,7 +118,7 @@ public BraveWebPage()
118118
/// <param name="url">The URL of the web page.</param>
119119
/// <param name="description">The description of the web page.</param>
120120
/// <param name="type">The type of the search result.</param>
121-
public BraveWebPage(string? title, string? url, string? description, string? type = null)
121+
public BraveWebPage(string? title, Uri? url, string? description, string? type = null)
122122
{
123123
this.Title = title;
124124
this.Url = url;
@@ -133,7 +133,8 @@ public BraveWebPage(string? title, string? url, string? description, string? typ
133133
/// <returns>A new BraveWebPage instance.</returns>
134134
internal static BraveWebPage FromWebResult(BraveWebResult result)
135135
{
136-
return new BraveWebPage(result.Title, result.Url, result.Description, result.Type)
136+
Uri? url = string.IsNullOrWhiteSpace(result.Url) ? null : new Uri(result.Url);
137+
return new BraveWebPage(result.Title, url, result.Description, result.Type)
137138
{
138139
Age = result.Age,
139140
PageAge = result.PageAge,

dotnet/src/Plugins/Plugins.Web/Tavily/TavilyTextSearch.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,11 @@ private async IAsyncEnumerable<object> GetResultsAsWebPageAsync(TavilySearchResp
569569
{
570570
foreach (var image in searchResponse.Images!)
571571
{
572-
// For images, create a basic TavilyWebPage representation
572+
//For images, create a basic TavilyWebPage representation
573+
Uri? imageUri = string.IsNullOrWhiteSpace(image.Url) ? null : new Uri(image.Url);
573574
yield return new TavilyWebPage(
574575
title: "Image Result",
575-
url: image.Url,
576+
url: imageUri,
576577
content: image.Description ?? string.Empty,
577578
score: 0.0
578579
);

dotnet/src/Plugins/Plugins.Web/Tavily/TavilyWebPage.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Copyright (c) Microsoft. All rights reserved.
22

3+
using System;
4+
35
namespace Microsoft.SemanticKernel.Plugins.Web.Tavily;
46

57
/// <summary>
@@ -16,7 +18,7 @@ public sealed class TavilyWebPage
1618
/// <summary>
1719
/// Gets or sets the URL of the web page.
1820
/// </summary>
19-
public string? Url { get; set; }
21+
public Uri? Url { get; set; }
2022

2123
/// <summary>
2224
/// Gets or sets the content/description of the web page.
@@ -78,7 +80,7 @@ public TavilyWebPage()
7880
/// <param name="content">The content/description of the web page.</param>
7981
/// <param name="score">The relevance score.</param>
8082
/// <param name="rawContent">The raw content (optional).</param>
81-
public TavilyWebPage(string? title, string? url, string? content, double score, string? rawContent = null)
83+
public TavilyWebPage(string? title, Uri? url, string? content, double score, string? rawContent = null)
8284
{
8385
this.Title = title;
8486
this.Url = url;
@@ -94,6 +96,7 @@ public TavilyWebPage(string? title, string? url, string? content, double score,
9496
/// <returns>A new TavilyWebPage instance.</returns>
9597
internal static TavilyWebPage FromSearchResult(TavilySearchResult result)
9698
{
97-
return new TavilyWebPage(result.Title, result.Url, result.Content, result.Score, result.RawContent);
99+
Uri? url = string.IsNullOrWhiteSpace(result.Url) ? null : new Uri(result.Url);
100+
return new TavilyWebPage(result.Title, url, result.Content, result.Score, result.RawContent);
98101
}
99102
}

0 commit comments

Comments
 (0)