Bug 6892 - If a URL has been entered without http://, it isn't correctly linked
Summary: If a URL has been entered without http://, it isn't correctly linked
Status: Signed Off
Alias: None
Product: Koha
Classification: Unclassified
Component: Cataloging (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Jan Kissig
QA Contact: Bugs List
URL:
Keywords:
: 23337 (view as bug list)
Depends on: 38096
Blocks:
  Show dependency treegraph
 
Reported: 2011-09-21 06:01 UTC by Robin Sheat
Modified: 2026-02-17 03:44 UTC (History)
6 users (show)

See Also:
GIT URL:
Initiative type: ---
Sponsorship status: ---
Comma delimited list of Sponsors:
Crowdfunding goal: 0
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
This enhancement checks for URLs in MARC21 data and, in case of a missing protocol (http or https), either: * adds a missing prefix if tag=856 and indicator 1=4 is set, * or omits the HTML anchor element (so it is not linked) On other $u subfields (for example, 505$u) the HTML anchor element is omitted when the protocol is missing. It also fixes the links where the TrackClicks system preference is used. Currently, when the prefix is missing, the active URL link is incorrect. For example, if bugs.koha-community.org is used, the actual URL is https://YOUR-CATALOG-URL/cgi-bin/koha/catalogue/bugs.koha-community.org
Version(s) released in:
Circulation function:


Attachments
Bug 6892: Fix links on MARCdetail.tt when protocol is missing (3.91 KB, patch)
2026-02-10 19:00 UTC, Jan Kissig
Details | Diff | Splinter Review
Bug 6892: Fix links on MARCdetail.tt when protocol is missing (3.96 KB, patch)
2026-02-13 18:13 UTC, David Nind
Details | Diff | Splinter Review
Bug 6892: Fix links on MARCdetail.tt when protocol is missing (3.96 KB, patch)
2026-02-16 09:29 UTC, Jan Kissig
Details | Diff | Splinter Review
Bug 6892: (follow-up) Fix urls in OPAC when TrackClicks is enabled (4.85 KB, patch)
2026-02-16 09:29 UTC, Jan Kissig
Details | Diff | Splinter Review
Bug 6892: Fix links on MARCdetail.tt when protocol is missing (3.96 KB, patch)
2026-02-17 03:41 UTC, David Nind
Details | Diff | Splinter Review
Bug 6892: (follow-up) Fix urls in OPAC when TrackClicks is enabled (4.90 KB, patch)
2026-02-17 03:41 UTC, David Nind
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Robin Sheat 2011-09-21 06:01:45 UTC
If a MARC record contains a URL, and that URL doesn't have http:// at the start of it, then the link isn't correctly generated. We should catch that and insert the http prefix.
Comment 1 Robin Sheat 2011-09-21 06:02:18 UTC
Probably best to do this on display, or both display and cataloguing.
Comment 2 Ian Walls 2011-09-21 15:33:16 UTC
In MARC21, we can only assume http:// if the first indicator of the 856 is 4.  The 856 can handle other protocols (remember that MARC predates the WWW by quite a few years).

From Library of Congress

0 - Email
1 - FTP
2 - Remote login (Telnet)
3 - Dial-up
4 - HTTP
7 - Method specified in subfield $2
Comment 3 Robin Sheat 2011-09-21 20:46:25 UTC
Ah, good point, I hadn't checked the spec. However, at the moment it seems (without checking) that Koha assumes the browser knows what the URL is, which can be wrong too.
Comment 4 Katrin Fischer 2019-05-04 10:52:50 UTC
Maybe a good first step would be to add http in case of first indicator = 4 and the URL doesn't start with that or https already and leave the content alone otherwise.
Comment 5 Katrin Fischer 2020-03-30 21:44:10 UTC
*** Bug 23337 has been marked as a duplicate of this bug. ***
Comment 6 David Cook 2022-12-06 01:53:33 UTC
I think that there could be a URL validator in the editor, but we shouldn't be auto-adding things to existing data I reckon.
Comment 7 David Cook 2022-12-06 01:54:22 UTC
I think bug 8609 might be a good successor to this one.
Comment 8 Katrin Fischer 2023-08-05 09:27:32 UTC
(In reply to David Cook from comment #7)
> I think bug 8609 might be a good successor to this one.

Only that it was closed ages ago. - Is this still something we should look into? I assume we would not change the data, but fix anytime we create a HTML link?
Comment 9 Nick Clemens (kidclamp) 2023-08-08 13:47:34 UTC
Still valid? Or fixed by bug 32794?
Comment 10 Jan Kissig 2026-02-09 11:46:36 UTC
(In reply to Nick Clemens (kidclamp) from comment #9)
> Still valid? Or fixed by bug 32794?

This is still valid for /cgi-bin/koha/catalogue/MARCdetail.pl

  
To recreate:
- add 856 ind1=4 $u=koha-community.org/ to a record
- on /cgi-bin/koha/catalogue/detail.pl it is prefixed with http://
- on /cgi-bin/koha/catalogue/MARCdetail.pl it wil result in http://main-intra.localhost/cgi-bin/koha/catalogue/koha-community.org/
Comment 11 Jan Kissig 2026-02-10 19:00:30 UTC Comment hidden (obsolete)
Comment 12 David Nind 2026-02-13 18:13:47 UTC Comment hidden (obsolete)
Comment 13 Jan Kissig 2026-02-16 09:29:55 UTC Comment hidden (obsolete)
Comment 14 Jan Kissig 2026-02-16 09:29:58 UTC Comment hidden (obsolete)
Comment 15 Jan Kissig 2026-02-16 09:34:59 UTC
The follow-up resolves 23337: Links without the protocol in the 856$u fail when using TrackClicks
Comment 16 David Nind 2026-02-17 03:41:07 UTC
Created attachment 193286 [details] [review]
Bug 6892: Fix links on MARCdetail.tt when protocol is missing

This patch will check for URLs in MARC21 data and in case of a missing protocol prefix
- either append a missing http prefix if tag=856 and indicator 1=4 is set,
- or omit the html anchor element
On other $u subfields (e.g. 505$u) the html anchor element is omitted when protocol is missing, regardless

Test plan:

a) edit a record set the following 856 fields:
 1. 856 ind1=4 $u = bugs.koha-community.org
 2. 856 $u = bugs.koha-community.org
 3. 856 $u = https://bugs.koha-community.org
 4. 505 $u = bugs.koha-community.org
 5. 505 $u = https://bugs.koha-community.org
b) save and go to records MARC view (MARCdetail.pl) and take a look at the links in tab 5 and 8
 1. links to http://main-intra.localhost/cgi-bin/koha/catalogue/bugs.koha-community.org/
 2. links to http://main-intra.localhost/cgi-bin/koha/catalogue/bugs.koha-community.org/
 3. links to https://bugs.koha-community.org/
 4. links to http://main-intra.localhost/cgi-bin/koha/catalogue/bugs.koha-community.org
 5. links to https://bugs.koha-community.org/
c) apply patch and reload MARCdetail.pl (maybe a restart_all is required)
d) verify that
 1. links to http://bugs.koha-community.org/ (because of indicator1=4)
 2. bugs.koha-community.org/ is displayed but not inside an html anchor element
 3. links https://bugs.koha-community.org/
 4. bugs.koha-community.org/ is displayed but not inside an html anchor element
 5. links to https://bugs.koha-community.org/

Signed-off-by: David Nind <david@davidnind.com>
Comment 17 David Nind 2026-02-17 03:41:10 UTC
Created attachment 193287 [details] [review]
Bug 6892: (follow-up) Fix urls in OPAC when TrackClicks is enabled

This patch fixes outgoing links from 856$u when system preference 'TrackClicks' is set and the URL is lacking the protocol prefix.

Test plan:

a) set system pref TrackClicks to 'Track' or 'Track anonymously'
b) edit a record (f.e. 262) and set the following 856 fields (the record from 1st patch is sufficient though):
 1. 856 ind1=4 $u = example.com
 2. 856 $u = example.com
 3. 856 $u = https://example.com
b) save and search for that record in OPAC.
c) on search results list (opac-search.pl) please check the links on that record:
 1. links to http://main.localhost/cgi-bin/koha/tracklinks.pl?uri=example.com&biblionumber=262 and does not work
 2. links to http://main.localhost/cgi-bin/koha/tracklinks.pl?uri=example.com&biblionumber=262 and does not work
 3. links to http://main.localhost/cgi-bin/koha/tracklinks.pl?uri=https://example.com&biblionumber=262 and works
d) click on the record to get to the detail page (opac-detail.pl) and check the links again (Online resources). They should be the same as in step c)

e) apply patch, call restart_all and redo step b) until d) verifying that
 1. is now prefixed with http:// and links to http://main.localhost/cgi-bin/koha/tracklinks.pl?uri=http://example.com&biblionumber=262 (works now)
 2. is now prefixed with http:// and links to http://main.localhost/cgi-bin/koha/tracklinks.pl?uri=http://example.com&biblionumber=262 (works now)
 3. still links to http://main.localhost/cgi-bin/koha/tracklinks.pl?uri=https://example.com&biblionumber=262

Signed-off-by: David Nind <david@davidnind.com>