Skip to content

Commit bb578c4

Browse files
committed
Guard GetCanonicalPath against null
Signed-off-by: ahmad <ahmadalgaidy@hotmail.com>
1 parent 567cec6 commit bb578c4

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/Lucene.Net.Tests/Support/IO/TestFileSupport.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,14 @@ public void TestGetCanonicalPath()
184184
}
185185
}
186186

187+
[Test, LuceneNetSpecific]
188+
public void TestGetCanonicalPathNullPath()
189+
{
190+
FileSystemInfo path = null;
191+
192+
Assert.Throws<ArgumentNullException>(() => path.GetCanonicalPath());
193+
}
194+
187195
private static string addTrailingSlash(string path)
188196
{
189197
if (Path.DirectorySeparatorChar == path[path.Length - 1])

src/Lucene.Net/Support/IO/FileSupport.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,11 @@ internal static string NewTempFileName(string prefix, string? suffix, string dir
536536
// LUCENENET NOTE: Implementation ported mostly from Apache Harmony
537537
public static string GetCanonicalPath(this FileSystemInfo path)
538538
{
539+
if (path is null)
540+
{
541+
throw new ArgumentNullException(nameof(path));
542+
}
543+
539544
string absPath = path.FullName; // LUCENENET NOTE: This internally calls GetFullPath(), which resolves relative paths
540545
byte[] result = Encoding.UTF8.GetBytes(absPath);
541546

0 commit comments

Comments
 (0)