💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Decode local file URIs before SafeOpen validation (#1524)
HuaTNA299bc0903e41
diff --git a/src/python/txtai/pipeline/data/safeopen.py b/src/python/txtai/pipeline/data/safeopen.pyindex d16b1403..7550914f 100644--- a/src/python/txtai/pipeline/data/safeopen.py+++ b/src/python/txtai/pipeline/data/safeopen.py@@ -6,6 +6,7 @@ import osimport tempfilefrom urllib.parse import urlparse+from urllib.request import url2pathnamefrom .urlretrieve import URLRetrieve@@ -51,8 +52,8 @@ class SafeOpen:(path, exists)"""- # Convert file urls to local paths- path = path.replace("file://", "")+ # Decode file URIs while preserving literal percent sequences in plain paths.+ path = url2pathname(path[7:]) if path.startswith("file://") else path# Check if this is a local file path or local file urlexists = os.path.exists(path)diff --git a/test/python/testpipeline/testdata/testtextractor.py b/test/python/testpipeline/testdata/testtextractor.pyindex 144f1d69..2f2c8d9b 100644--- a/test/python/testpipeline/testdata/testtextractor.py+++ b/test/python/testpipeline/testdata/testtextractor.py@@ -6,6 +6,7 @@ import osimport tempfileimport unittest+from pathlib import Pathfrom unittest.mock import patchfrom urllib.error import URLError@@ -67,6 +68,19 @@ class TestTextractor(unittest.TestCase):# Check number of sections is as expectedself.assertEqual(len(sections), 2)+ def testFileURI(self):+ """+ Test encoded file URIs and plain paths with literal percent sequences.+ """++ with tempfile.TemporaryDirectory() as directory:+ path = Path(directory) / "notes %20 #1.html"+ path.write_text("<html><body><p>research note</p></body></html>", encoding="utf-8")+ textractor = Textractor(backend=None)++ self.assertEqual(textractor(str(path)), "research note")+ self.assertEqual(textractor(path.as_uri()), "research note")+def testDownloadError(self):"""Test failed remote retrieval leaves no temporary file