DOCXToDocument drops URL fragments stored separately in Word hyperlinks
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 75/100
Direzione di ricerca
La gestione dei link si trova in _process_links_in_paragraph() nel convertitore DOCX, che legge Hyperlink.address; la issue segnala che Hyperlink.url mantiene il frammento w:anchor memorizzato separatamente. Inizia controllando lo script di riproduzione e i test del convertitore DOCX. È completato quando sia link_format="markdown" sia "plain" mantengono il frammento, link_format="none" resta invariato e un test di regressione copre un hyperlink con w:anchor.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
DOCXToDocument drops the section part of an external hyperlink when Word stores the URL fragment separately in w:anchor. This happens with both link_format="markdown" and "plain".
For example, a link to https://example.org/manual#refund-policy becomes https://example.org/manual. The link text is still there, but the extracted link no longer points to the intended section. The same URL works when the fragment is stored directly in the relationship address.
The python-docx documentation explains that Word uses both representations. I found this with a small generated DOCX, rather than a production document.
Error message
No exception; the URL fragment is silently omitted.
Expected behavior
The complete external link target should be preserved in both output formats:
markdown '[Refund policy](https://example.org/manual#refund-policy)'
plain 'Refund policy (https://example.org/manual#refund-policy)'
To reproduce
from io import BytesIO
from docx import Document as WordDocument
from docx.opc.constants import RELATIONSHIP_TYPE
from docx.oxml import OxmlElement
from docx.oxml.ns import qn
from haystack.components.converters import DOCXToDocument
from haystack.dataclasses import ByteStream
doc = WordDocument()
paragraph = doc.add_paragraph()
rid = paragraph.part.relate_to(
"https://example.org/manual", RELATIONSHIP_TYPE.HYPERLINK, is_external=True
)
link = OxmlElement("w:hyperlink")
link.set(qn("r:id"), rid)
link.set(qn("w:anchor"), "refund-policy")
run = OxmlElement("w:r")
text = OxmlElement("w:t")
text.text = "Refund policy"
run.append(text)
link.append(run)
paragraph._p.append(link)
buffer = BytesIO()
doc.save(buffer)
source = ByteStream(data=buffer.getvalue())
for mode in ("markdown", "plain"):
result = DOCXToDocument(link_format=mode).run(sources=[source])
print(mode, repr(result["documents"][0].content))
Actual output:
markdown '[Refund policy](https://example.org/manual)'
plain 'Refund policy (https://example.org/manual)'
Additional context / proposed fix
_process_links_in_paragraph() uses Hyperlink.address, which excludes a separately stored fragment. Hyperlink.url includes it. I tried using url locally: all nine reproduction cases passed, including ordinary URLs, inline fragments, and link_format="none". The 40 existing DOCX converter tests also passed. These were focused local checks, rather than the full test suite or CI.
Would you be happy for me to pick this up and send a focused fix? I would add a regression test and release note. I'll wait for your confirmation before opening a PR.
I used Codex to help investigate the behavior and run the local checks.
FAQ check
- Checked the FAQ.
System
- OS: macOS, arm64
- Python: 3.13.9
- Haystack:
3.4.0-rc0, tested at5fa8cff71d665ca9d179bd222965adaaefca0db7 - python-docx:
1.2.0 - Checks run through Hatch
1.18.1
- Lingua principale
- Python
- Stelle
- 26.9k
- Fork
- 3.4k
- Merge medio
- 21h 54m
- PR unite (30g)
- 211
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di deepset-ai/haystack
-
MetaFieldRanker accepts NaN weights and returns NaN scoresForse già presa @priy-anshugupta l’ha presa 2 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
deepset-ai/haystack#13507 ·
I maintainer di solito rispondono entro 1 giorno
-
CSVToDocument accepts an unsupported conversion_mode and silently converts in row modeForse già presa @Lesereingrape l’ha presa 31 giorni fa. ApertaP3
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
deepset-ai/haystack#13070 ·
I maintainer di solito rispondono entro 1 giorno
-
PPTXToDocument drops soft line breaks when link_format is markdown or plainForse già presa @bogdankostic l’ha presa 21 giorni fa. ApertaP3
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
deepset-ai/haystack#13043 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
InMemoryDocumentStore: count_unique_metadata_by_filter and get_metadata_field_unique_values disagree on int/float/bool valuesForse già presa @julian-risch l’ha presa 31 giorni fa. ApertaP3
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
deepset-ai/haystack#13040 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
AutoMergingRetriever raises ValueError when a matched document has no parent (for example the root document)Forse già presa @julian-risch l’ha presa 33 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
deepset-ai/haystack#13029 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di deepset-ai/haystack
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
huggingface/smolagents#3106 ·
I maintainer di solito rispondono entro 2 giorni
-
area:scripts area:tests bug priority:later
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Ikalus1988/MisakaNet#4358 ·
I maintainer di solito rispondono entro 1 giorno
-
Discovered ports from service discovery are never propagated to modules in Module.load()Forse già presa @vishalmore90 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
OWASP/Nettacker#1828 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
aws-samples/sample-per-model-bedrock#708 ·
I maintainer di solito rispondono entro 1 giorno
-
maintenance
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100