Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: escape double quotes in .xls cell values like the .xlsx path (#42049)

Harsh Kashyap112e33a6651a
diff --git a/api/core/rag/extractor/excel_extractor.py b/api/core/rag/extractor/excel_extractor.py
index eafc81b0e12..5d5316dc1a3 100644
--- a/api/core/rag/extractor/excel_extractor.py
+++ b/api/core/rag/extractor/excel_extractor.py
@@ -143,7 +143,10 @@ class ExcelExtractor(BaseExtractor):
page_content = []
for k, v in series_row.items():
if pd.notna(v):
- page_content.append(f'"{k}":"{v}"')
+ # Escape embedded double quotes like the .xlsx branch
+ # does, so quoted cell values do not corrupt the row.
+ value = str(v).replace('"', '\\"')
+ page_content.append(f'"{k}":"{value}"')
documents.append(
Document(page_content=";".join(page_content), metadata={"source": self._file_path})
)
diff --git a/api/tests/unit_tests/core/rag/extractor/test_excel_extractor.py b/api/tests/unit_tests/core/rag/extractor/test_excel_extractor.py
index 2797d55d39f..ddd7907727a 100644
--- a/api/tests/unit_tests/core/rag/extractor/test_excel_extractor.py
+++ b/api/tests/unit_tests/core/rag/extractor/test_excel_extractor.py
@@ -260,6 +260,21 @@ class TestExcelExtractor:
assert docs[0].page_content == '"A":"x";"B":"1.0"'
assert docs[0].metadata == {"source": "/tmp/sample.xls"}
+ def test_extract_xls_escapes_double_quotes_like_xlsx(self, monkeypatch: pytest.MonkeyPatch):
+ class FakeExcelFile:
+ sheet_names = ["Sheet1"]
+
+ def parse(self, sheet_name):
+ return pd.DataFrame([{"note": 'he said "hi"', "plain": "text"}])
+
+ monkeypatch.setattr(pd, "ExcelFile", lambda path, engine=None: FakeExcelFile())
+
+ extractor = ExcelExtractor("/tmp/sample.xls")
+ docs = extractor.extract()
+
+ assert len(docs) == 1
+ assert docs[0].page_content == '"note":"he said \\"hi\\"";"plain":"text"'
+
def test_extract_unsupported_extension_raises(self):
extractor = ExcelExtractor("/tmp/sample.txt")