Skip to content

Exclude trailing punctuation from auto-linked URLs in descriptions - #202

Open
kosarko wants to merge 2 commits into
clarin-v7from
fix-description-link-trailing-punctuation
Open

kosarko wants to merge 2 commits into
clarin-v7from
fix-description-link-trailing-punctuation

Conversation

@kosarko

@kosarko kosarko commented Nov 13, 2026

Copy link
Copy Markdown
Member

Problem description

URLs in an item description are auto-linked by makeLinks(). When a URL ends a sentence or is followed by a comma, the punctuation became part of the link, so the link was broken. For example Consolidated 2.0 http://hdl.handle.net/11234/1-5813. linked to http://hdl.handle.net/11234/1-5813. (with the dot).

Addresses starting with www. also got a relative href, so they resolved under the repository's own host.

Analysis

The URL regex takes everything up to whitespace or ). The fix strips trailing . , ; : ! ? ' " from the match and renders it as plain text after the anchor. Punctuation inside a URL is untouched. www. addresses now get an http:// href, with the visible text unchanged.

makeLinks() is used by the description field on the simple item page and by the full item page; both are fixed.

Testing

Unit tests added in clarin-shared-util.spec.ts.

Checked in the browser against a local stack with a description of
Consolidated 2.0 http://hdl.handle.net/11234/1-5813. See https://github.com/ufal/perin, then visit www.example.org. Query link https://example.org/a.b?x=1;y=2#c stays whole (also http://example.com/x).

Text in description href before href after
http://hdl.handle.net/11234/1-5813. http://hdl.handle.net/11234/1-5813. http://hdl.handle.net/11234/1-5813
https://github.com/ufal/perin, https://github.com/ufal/perin, https://github.com/ufal/perin
www.example.org. www.example.org. (relative) http://www.example.org
https://example.org/a.b?x=1;y=2#c unchanged unchanged
(also http://example.com/x). http://example.com/x http://example.com/x

Same result on the simple and the full item page.

Problems

Not changed here: the full item page replaces every ; in a metadata value with a space after linking (dsReplace: [';', ' ']), so a URL containing ; is cut at the ; on that page only. This behaves the same before and after this PR.

Copilot review

  • Requested review from Copilot

makeLinks() included a sentence-ending period or comma in the link
(e.g. "http://hdl.handle.net/11234/1-5813."), producing broken links.
Strip trailing punctuation and render it after the anchor. Also give
www.* links an absolute http:// href instead of a relative one.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Trailing-semicolon trimming corrupts HTML character references, producing incorrect link destinations and visible text when descriptions are rendered through innerHTML.

1 open issue
What changed in this PR

Improves automatic URL linking in the shared helper used by item descriptions and full-item metadata.

Changes:

  • Moves trailing sentence punctuation outside generated links.
  • Adds http:// to www. destinations without changing their visible text.
  • Adds unit tests for punctuation handling and absolute URLs.
File Description
src/​app/​shared/​clarin-shared-util.ts Separates trailing punctuation and normalizes www. link destinations.
src/​app/​shared/​clarin-shared-util.spec.ts Tests trailing punctuation, internal punctuation, and www. links.

Review effort: Balanced

Comment thread src/app/shared/clarin-shared-util.ts Resolved
…ked URLs

makeLinks() output is rendered through innerHTML, so stripping the ';'
from a URL ending in e.g. "&" or "/" changed the link target.
@kosarko

kosarko commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

@stranak FYI: this fixes links in item descriptions that swallowed the punctuation after a URL, e.g. http://hdl.handle.net/11234/1-5813. at the end of a sentence was linked including the dot and so led nowhere. The dot or comma now stays outside the link.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the shared URL auto-linking changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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.

3 participants