load_from_url includes URL query strings and fragments in the file suffix, misrouting PDF responses
Self Checks
- I have read the Contributing Guide and Language Policy.
- This is only for bug report, if you would like to ask a question, please head to Discussions.
- I have searched for existing issues search for existing issues, including closed ones.
- I confirm that I am using English to submit this report, otherwise it will be closed.
- 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
- Please do not modify this template :) and fill in all the required fields.
Dify version
main at 0bd950fd01e9d0b357601fb1a418673465304ede (api/pyproject.toml: 1.17.1)
Cloud or Self Hosted
Self Hosted (Source)
Steps to reproduce
Reproduced at source level in the locked Python 3.12.11 environment with the real module imported, mocked HTTP responses and concrete extractors; no deployed Dify instance or cloud service was used.
ExtractProcessor.load_from_url derives the temporary file suffix with Path(url).suffix. This includes the query string or fragment rather than reading only the URL path.
After uv sync --project api --dev --frozen, run this from the repository root. It imports the real module and executes its loader and routing code, mocking only the HTTP response, ETL configuration, and concrete PDF/text extractors:
PYTHONPATH=api uv run --project api --no-sync python <<'PY'
from types import SimpleNamespace
from unittest.mock import patch
from core.rag.extractor import extract_processor as processor_module
from core.rag.extractor.extract_processor import ExtractProcessor
response = SimpleNamespace(headers={'Content-Type': 'application/pdf'}, content=b'%PDF-1.1 body')
failed = []
with (
patch.object(processor_module.remote_fetcher, 'make_request', return_value=response),
patch.object(processor_module.dify_config, 'ETL_TYPE', 'dify'),
patch.object(processor_module, 'PdfExtractor') as pdf,
patch.object(processor_module, 'TextExtractor') as text,
):
pdf.return_value.extract.return_value = [SimpleNamespace(page_content='PDF')]
text.return_value.extract.return_value = [SimpleNamespace(page_content='TEXT')]
for url in (
'https://example.com/report.pdf',
'https://example.com/report.pdf?X-Amz-Signature=abc',
'https://example.com/report.pdf#page=2',
'https://example.com/download?filename=report.txt',
):
result = ExtractProcessor.load_from_url(url, return_text=True)
print(url, '->', result)
if result != 'PDF':
failed.append(url)
assert not failed, f'{len(failed)} URLs selected the wrong extractor'
PYObserved output on the baseline above:
https://example.com/report.pdf -> PDF
https://example.com/report.pdf?X-Amz-Signature=abc -> TEXT
https://example.com/report.pdf#page=2 -> TEXT
https://example.com/download?filename=report.txt -> TEXT
AssertionError: 3 URLs selected the wrong extractorThe clean .pdf control case works; all three query/fragment cases select the wrong extractor with the same Content-Type: application/pdf. The existing test_extract_processor.py suite passes (48 tests), so these cases need regression coverage.
✔️ Expected Behavior
Determine a URL's file suffix from its path only. A PDF path with a query string or fragment should retain .pdf and select PdfExtractor. If the path has no suffix, use the existing response-header fallback; dots in a query parameter must not override Content-Type: application/pdf.
Keep the full original URL, including its query string, when making the HTTP request.
❌ Actual Behavior
The temporary file suffix is .pdf?X-Amz-Signature=abc or .pdf#page=2, so the exact .pdf comparison in extract() does not match and the downloaded PDF is routed to TextExtractor. These nonempty suffixes also bypass the response-header fallback. A suffix from a query parameter (for example ?filename=report.txt) can incorrectly override the response media type.
This affects PDF URLs with signed query parameters and PDF links with fragments. The resulting text extraction can return PDF source/binary content or fail to decode, depending on the bytes; this report verifies the wrong extractor selection rather than claiming a deployed ingestion result.
Related #42363 / #42364 fixed parameters in Content-Type, but the separate Path(url).suffix path remains unchanged on the baseline above.
I can contribute a minimal path-only parsing fix and regression tests for query strings, fragments, and header fallback.
Prepared with AI assistance (Codex); the reproduction scope and limitations are described above.
Source: langgenius/dify