Skip to content

Read a typographic hyphen in a PDF link target as a plain hyphen - #293

Open
thesanogoeffect wants to merge 2 commits into
mainfrom
fix/link-target-unicode-hyphen
Open

thesanogoeffect wants to merge 2 commits into
mainfrom
fix/link-target-unicode-hyphen

Conversation

@thesanogoeffect

Copy link
Copy Markdown
Member

What this fixes

Since #283 and #284 a URL's href is taken from the PDF's own link annotation when one covers the printed link. Some publishers write that target with the typographic hyphen U+2010 where the address has "-". The DOI printed as 10.13020/1f35-rn20 then came out as https://doi.org/10.13020/1f35%E2%80%90rn20, which does not resolve. bibr 0.7.3 exported the plain hyphen, so this came in with the link-target work that 0.9.2 ships.

_target() in bibr/structure/table_links.py now reads U+2010 and U+2011 in a link target as "-", as the character or percent-encoded, and drops a soft hyphen. A dash or a minus sign is kept, since an address can mean one.

Measured

--fast on the CPU over the 24 papers of the BES link comparison (metacheck #634), origin/main against this branch, every export pair compared:

url row of 10.1111/2041-210X.13821 before after
url[11] https://doi.org/10.13020/1f35%E2%80%90rn20 https://doi.org/10.13020/1f35-rn20
url[15] https://doi.org/10.1111/j.2517%E2%80%906161.1977.tb01619.x https://doi.org/10.1111/j.2517-6161.1977.tb01619.x
url[16] https://doi.org/10.1007/s10463%E2%80%90014%E2%80%900493%E2%80%906 https://doi.org/10.1007/s10463-014-0493-6
url[21] https://doi.org/10.1007/978%E2%80%900%E2%80%90387%E2%80%9098135%E2%80%902 https://doi.org/10.1007/978-0-387-98135-2
  • On those four rows link_text goes from the printed address to null: the printed link now is the target, so it is no longer a repaired link. 0.7.3 exported them the same way.
  • Nothing else differs in the 24 exports (1,199 url rows) apart from timestamps and timings.
  • Across the 2,116 link annotations of the 24 PDFs, U+2010 occurs in 5, always percent-encoded. U+2011 and the soft hyphen were not observed; they are covered because they are the same kind of character.

Not covered

  • LinkTargets.printed_forms still keeps U+2010 in a target, so such a target cannot help join a link wrapped over a line break.
  • An en dash read from the printed text (http://www.R–project.org in one paper) is body-text handling and is left alone.
  • The gold cohort was not run: the change only alters a target that holds one of these characters.

Tests

tests/test_table_links.py gains 17 cases on made-up addresses (32 pass); 471 tests pass across the 13 files that cover link targets, text links, the document layer and the url table. ruff check and ruff format --check are clean.

"Dependency and source security" will fail here until #285 lands: the audit exception for PYSEC-2026-3447 on main expired on 23 November.

Some publishers' PDFs write a link annotation's target with the hyphen
U+2010 where the address has "-". repair_links_from_targets compares a
printed link with the targets after squeezing out hyphens, so the printed
"https://doi.org/10.13020/1f35-rn20" matched the target
"https://doi.org/10.13020/1f35%E2%80%90rn20" and took its spelling: the
url table's href did not resolve, and the printed address became link_text.

_target now reads U+2010 and U+2011 in a target as "-", as the character
or percent-encoded, and drops a soft hyphen. The printed link is then the
target itself and is left alone. A dash or minus sign is kept, since an
address can mean one. The same reading applies to the targets of the
annotations on a table.

On the 24 BES papers of the link comparison (--fast, CPU) this changes
four url rows of 10.1111/2041-210X.13821 and nothing else.
@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.14%. Comparing base (4bfeebc) to head (f68dbbd).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #293   +/-   ##
=======================================
  Coverage   91.14%   91.14%           
=======================================
  Files         344      344           
  Lines       73647    73649    +2     
  Branches    13667    13667           
=======================================
+ Hits        67125    67129    +4     
+ Misses       4041     4040    -1     
+ Partials     2481     2480    -1     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…leased

The automatic merge filed the note under 0.9.2, which main has already closed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant