You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2026/08/30 06:34:11 UTC
(lucenenet) branch master updated: Guard GetCanonicalPath against null (#1440)
This is an automated email from the ASF dual-hosted git repository.
NightOwl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
The following commit(s) were added to refs/heads/master by this push:
new 8055cfc00 Guard GetCanonicalPath against null (#1440)
8055cfc00 is described below
commit 8055cfc00761f35515de422c670012b5f7784136
Author: tomatotomata <Ah...@hotmail.com>
AuthorDate: Sun Aug 30 09:34:05 2026 +0300
Guard GetCanonicalPath against null (#1440)
Signed-off-by: ahmad <ah...@hotmail.com>
---
src/Lucene.Net.Tests/Support/IO/TestFileSupport.cs | 8 ++++++++
src/Lucene.Net/Support/IO/FileSupport.cs | 5 +++++
2 files changed, 13 insertions(+)
diff --git a/src/Lucene.Net.Tests/Support/IO/TestFileSupport.cs b/src/Lucene.Net.Tests/Support/IO/TestFileSupport.cs
index 824f22ee2..f45932a07 100644
--- a/src/Lucene.Net.Tests/Support/IO/TestFileSupport.cs
+++ b/src/Lucene.Net.Tests/Support/IO/TestFileSupport.cs
@@ -184,6 +184,14 @@ public void TestGetCanonicalPath()
}
}
+ [Test, LuceneNetSpecific]
+ public void TestGetCanonicalPathNullPath()
+ {
+ FileSystemInfo path = null;
+
+ Assert.Throws<ArgumentNullException>(() => path.GetCanonicalPath());
+ }
+
private static string addTrailingSlash(string path)
{
if (Path.DirectorySeparatorChar == path[path.Length - 1])
diff --git a/src/Lucene.Net/Support/IO/FileSupport.cs b/src/Lucene.Net/Support/IO/FileSupport.cs
index 662edee7c..7edde314e 100644
--- a/src/Lucene.Net/Support/IO/FileSupport.cs
+++ b/src/Lucene.Net/Support/IO/FileSupport.cs
@@ -536,6 +536,11 @@ internal static string NewTempFileName(string prefix, string? suffix, string dir
// LUCENENET NOTE: Implementation ported mostly from Apache Harmony
public static string GetCanonicalPath(this FileSystemInfo path)
{
+ if (path is null)
+ {
+ throw new ArgumentNullException(nameof(path));
+ }
+
string absPath = path.FullName; // LUCENENET NOTE: This internally calls GetFullPath(), which resolves relative paths
byte[] result = Encoding.UTF8.GetBytes(absPath);