Skip to content

Commit

Permalink
handle bad paths in sys.path
Browse files Browse the repository at this point in the history
  • Loading branch information
lostmsu committed May 10, 2024
1 parent 32051cb commit fe3ca4f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/runtime/AssemblyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ static IEnumerable<string> FindAssemblyCandidates(string name)
}
else
{
int invalidCharIndex = head.IndexOfAny(Path.GetInvalidPathChars());
if (invalidCharIndex >= 0)
{
Exceptions.warn($"Path entry '{head}' has invalid char at position {invalidCharIndex}", Exceptions.ValueError);
continue;
}
path = Path.Combine(head, name);
}

Expand Down
14 changes: 14 additions & 0 deletions tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,20 @@ def test_clr_add_reference():
with pytest.raises(FileNotFoundException):
AddReference("somethingtotallysilly")


def test_clr_add_reference_bad_path():
import sys
from clr import AddReference
from System.IO import FileNotFoundException
bad_path = "hello\0world"
sys.path.append(bad_path)
try:
with pytest.raises(FileNotFoundException):
AddReference("test_clr_add_reference_bad_path")
finally:
sys.path.remove(bad_path)


def test_clr_get_clr_type():
"""Test clr.GetClrType()."""
from clr import GetClrType
Expand Down

0 comments on commit fe3ca4f

Please sign in to comment.