Repository navigation
Conversation
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.
There was a problem hiding this comment.
🟡 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://towww.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
…ked URLs makeLinks() output is rendered through innerHTML, so stripping the ';' from a URL ending in e.g. "&" or "/" changed the link target.
Member
Author
|
@stranak FYI: this fixes links in item descriptions that swallowed the punctuation after a URL, e.g. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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 exampleConsolidated 2.0 http://hdl.handle.net/11234/1-5813.linked tohttp://hdl.handle.net/11234/1-5813.(with the dot).Addresses starting with
www.also got a relativehref, 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 anhttp://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).hrefbeforehrefafterhttp://hdl.handle.net/11234/1-5813.http://hdl.handle.net/11234/1-5813.http://hdl.handle.net/11234/1-5813https://github.com/ufal/perin,https://github.com/ufal/perin,https://github.com/ufal/perinwww.example.org.www.example.org.(relative)http://www.example.orghttps://example.org/a.b?x=1;y=2#c(also http://example.com/x).http://example.com/xhttp://example.com/xSame 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