From 57a54a09991a628bf0798abe323f5f451a490738 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Mar 2026 21:43:27 +0000 Subject: [PATCH 1/2] Initial plan From 4d058563f87e192cbbbeaedd8b2ad84c08fe0039 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Mar 2026 21:48:31 +0000 Subject: [PATCH 2/2] Fix ItemWithPath to throw on null/empty/whitespace path Co-authored-by: lramosvea <77297467+lramosvea@users.noreply.github.com> --- .../DriveItemRequestBuilderExtensions.cs | 24 ++++++++------ .../DriveItemRequestBuilderExtensionsTests.cs | 32 +++++++++++++++++++ 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.Graph/Extensions/DriveItemRequestBuilderExtensions.cs b/src/Microsoft.Graph/Extensions/DriveItemRequestBuilderExtensions.cs index 4dec45ad515..8b490e49a90 100644 --- a/src/Microsoft.Graph/Extensions/DriveItemRequestBuilderExtensions.cs +++ b/src/Microsoft.Graph/Extensions/DriveItemRequestBuilderExtensions.cs @@ -44,12 +44,14 @@ public static class DriveItemRequestBuilderExtensions /// public static CustomDriveItemItemRequestBuilder ItemWithPath(this Microsoft.Graph.Drives.Item.Root.RootRequestBuilder rootRequestBuilder, string path) { - if (!string.IsNullOrEmpty(path)) + if (path is null) + throw new ArgumentNullException(nameof(path)); + if (string.IsNullOrWhiteSpace(path)) + throw new ArgumentException("path cannot be empty or whitespace.", nameof(path)); + + if (!path.StartsWith("/")) { - if (!path.StartsWith("/")) - { - path = string.Format("/{0}", path); - } + path = string.Format("/{0}", path); } var requestInformation = rootRequestBuilder.ToGetRequestInformation(); @@ -67,12 +69,14 @@ public static CustomDriveItemItemRequestBuilder ItemWithPath(this Microsoft.Grap /// public static CustomDriveItemItemRequestBuilder ItemWithPath(this Microsoft.Graph.Drives.Item.Items.Item.DriveItemItemRequestBuilder rootRequestBuilder, string path) { - if (!string.IsNullOrEmpty(path)) + if (path is null) + throw new ArgumentNullException(nameof(path)); + if (string.IsNullOrWhiteSpace(path)) + throw new ArgumentException("path cannot be empty or whitespace.", nameof(path)); + + if (!path.StartsWith("/")) { - if (!path.StartsWith("/")) - { - path = string.Format("/{0}", path); - } + path = string.Format("/{0}", path); } var requestInformation = rootRequestBuilder.ToGetRequestInformation(); diff --git a/tests/Microsoft.Graph.DotnetCore.Test/Requests/Extensions/DriveItemRequestBuilderExtensionsTests.cs b/tests/Microsoft.Graph.DotnetCore.Test/Requests/Extensions/DriveItemRequestBuilderExtensionsTests.cs index edc08ec2e5f..d8d518415e3 100644 --- a/tests/Microsoft.Graph.DotnetCore.Test/Requests/Extensions/DriveItemRequestBuilderExtensionsTests.cs +++ b/tests/Microsoft.Graph.DotnetCore.Test/Requests/Extensions/DriveItemRequestBuilderExtensionsTests.cs @@ -141,5 +141,37 @@ public void ItemByPath_BuildRequestWithNestedPathSlashAndMoreThanOneParameter() Assert.NotNull(itemRequestInformation); Assert.Equal(expectedRequestUri, itemRequestInformation.URI); } + [Fact] + public void ItemByPath_ThrowsArgumentNullException_WhenPathIsNull_Root() + { + var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object); + Assert.Throws(() => graphServiceClient.Drives["driveId"].Root.ItemWithPath(null)); + } + + [Theory] + [InlineData("")] + [InlineData(" ")] + public void ItemByPath_ThrowsArgumentException_WhenPathIsEmptyOrWhitespace_Root(string path) + { + var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object); + Assert.Throws(() => graphServiceClient.Drives["driveId"].Root.ItemWithPath(path)); + } + + [Fact] + public void ItemByPath_ThrowsArgumentNullException_WhenPathIsNull_DriveItem() + { + var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object); + Assert.Throws(() => graphServiceClient.Drives["driveId"].Items["itemId"].ItemWithPath(null)); + } + + [Theory] + [InlineData("")] + [InlineData(" ")] + public void ItemByPath_ThrowsArgumentException_WhenPathIsEmptyOrWhitespace_DriveItem(string path) + { + var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object); + Assert.Throws(() => graphServiceClient.Drives["driveId"].Items["itemId"].ItemWithPath(path)); + } + } }