Skip to content

[BUGFIX] Improve DOI handling - #91

Merged
tinzog merged 4 commits into
in2code-de:typo3-13from
zecm-via:bugfix/doi-prefix
Nov 12, 2026
Merged

tinzog merged 4 commits into
in2code-de:typo3-13from
zecm-via:bugfix/doi-prefix

Conversation

@YKWeyer

@YKWeyer YKWeyer commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Issue

Most of the DOIs imported by our editors do not respect the expected DOI format (starting with 10.), leading to incorrect URLs being generated in the frontend (the most common being https://dx.doi.org/https://doi.org/10. …, because editors save the entire URL in the DOI field).

Suggested changes

  • Add a placeholder to the DOI input, showing the expected format
  • Strip most common invalid prefixes when getting the DOI of a publication entry
  • Generate a link to doi.org only when the returned DOI is matching the expected format (starting with 10.)
    • If it is not the case, then the value of the DOI will be outputted as text, as a fallback
  • Minor improvement: use doi.org instead of dx.doi.org according to the DOI Resolution Documentation:

    The proxy service (both doi.org and the earlier but no longer preferred dx.doi.org) is accessible …

Resolves #93

tinzog added a commit that referenced this pull request Nov 12, 2026
Follow-up to #91, which strips prefixes from DOIs and links only
values that look like a DOI.

- Move normalization, validation and URL generation into the new DoiUtility; Publication::getDoi() returns the
  normalized value and the new Publication::getDoiUrl() the resolver URL, or an empty string for an invalid DOI.
- Remove the f:startsWith check from LinkBlock.html and LinkBlock-Inline.html. The ViewHelper exists only since
  typo3fluid/fluid 4.5, so the citation list failed on early TYPO3 13.4 releases. The partials now check doiUrl.
- Strip LaTeX \url{...} including the braces, combined prefixes such as "DOI: https://doi.org/...",
  www.doi.org and "DOI 10...." with a space. Drop the multiline flag, so prefixes are removed at the start only.
- Accept only values matching 10.<registrant code>/<suffix without whitespace>, so text such as "10. Auflage" or
  values with several lines are shown as text instead of a broken link.
- Percent-encode the DOI suffix in the resolver URL, so DOIs containing #, ?, <, > or ; resolve correctly.

Related: #93
Related: https://projekte.in2code.de/issues/85317
@tinzog
tinzog merged commit 124f848 into in2code-de:typo3-13 Nov 12, 2026
9 checks passed
@tinzog

tinzog commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Thanks a lot for this PR, @YKWeyer! Wrong DOI values from editors pose a real problem .
We merged the PR into typo3-13 and added two follow-up commits:

  • 4e3968f [BUGFIX] Fix DOI normalization and link generation without f:startsWith
  • 7de22a2 [TEST] Add unit and functional tests for DOI handling

What changed:

  • f:startsWith: This ViewHelper only exists since typo3fluid/fluid 4.5. Early TYPO3 13.4 releases ship an older Fluid version, so the citation list failed there. The check is now done in PHP: Publication::getDoiUrl() returns the resolver URL, or an empty string if the DOI is invalid. The partials only check {publication.doiUrl}.
  • Cleanup: Cleaning, validation and URL building are now in a new DoiUtility. It also handles \url{…} including the braces, combined prefixes such as DOI: https://doi.org/…, www.doi.org and multi-line values.
  • Validation: A value counts as a DOI only if it matches 10./, so text like "10. Auflage" is no longer linked.
  • Encoding: Characters like #, ?, <, > and ; in the DOI are encoded in the link, so these DOIs open correctly at doi.org.
  • Tests: We added unit tests for the utility and functional tests for both link block partials.

Thanks again for your contribution!

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.

Broken DOI links when the DOI field contains a URL or prefix

2 participants