Bug 39307

Summary: console.error on circ/circulation.pl page
Product: Koha Reporter: Lucas Gass (lukeg) <lucas>
Component: CirculationAssignee: Eric Phetteplace <ephetteplace>
Status: Pushed to stable --- QA Contact: Brendan Lawlor <blawlor>
Severity: minor    
Priority: P5 - low CC: blawlor, ephetteplace, fridolin.somers, gmcharlt, jonathan.druart, kyle.m.hall, phil
Version: Main   
Hardware: All   
OS: All   
GIT URL: Change sponsored?: ---
Patch complexity: Trivial patch Documentation contact:
Documentation submission: Text to go in the release notes:
Version(s) released in:
25.05.00,24.11.07
Circulation function:
Bug Depends on: 37407    
Bug Blocks:    
Attachments: Bug 39307: Check to make sure there is a document.referrer
Bug 39307: Check to make sure there is a document.referrer
Bug 39307: Check to make sure there is a document.referrer
Bug 39307: Check to make sure there is a document.referrer
Bug 39307: Check to make sure there is a document.referrer
Bug 39307: Check to make sure there is a document.referrer

Description Lucas Gass (lukeg) 2025-03-11 16:52:47 UTC
To recreate:

1. Navigate to circ/circulation.pl?borrowernumber=X
2. See the console error `document.referrer.split(...)[1] is undefined`
Comment 1 Lucas Gass (lukeg) 2025-03-11 16:54:43 UTC
Created attachment 179173 [details] [review]
Bug 39307: Check to make sure there is a document.referrer

To test:
1. Navigate to circ/circulation.pl?borrowernumber=X
2. See the console error `document.referrer.split(...)[1] is undefined`
3. APPLY PATCH
4. JS error should be gone
Comment 2 Phil Ringnalda 2025-03-14 01:16:04 UTC
Created attachment 179298 [details] [review]
Bug 39307: Check to make sure there is a document.referrer

To test:
1. Navigate to circ/circulation.pl?borrowernumber=X
2. See the console error `document.referrer.split(...)[1] is undefined`
3. APPLY PATCH
4. JS error should be gone

Signed-off-by: Phil Ringnalda <phil@chetcolibrary.org>
Comment 3 Brendan Lawlor 2025-03-24 13:40:41 UTC
Created attachment 179638 [details] [review]
Bug 39307: Check to make sure there is a document.referrer

To test:
1. Navigate to circ/circulation.pl?borrowernumber=X
2. See the console error `document.referrer.split(...)[1] is undefined`
3. APPLY PATCH
4. JS error should be gone

Signed-off-by: Phil Ringnalda <phil@chetcolibrary.org>
Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Comment 4 Jonathan Druart 2025-03-24 13:44:24 UTC
Oops, sorry for the messy changes.

Thanks for the fast QA, Brendan!
Comment 5 Brendan Lawlor 2025-03-24 13:44:53 UTC
Makes sense to check if there is a referrer before running that code block. Passing QA. 

Thanks!
Comment 6 Eric Phetteplace 2025-03-25 17:13:33 UTC
Unfortunately this fails when 1) there is a referrer and 2) it is not additem.pl. While document.referrer is defined `document.referrer.split(window.location.origin + '/cgi-bin/koha/cataloguing/additem.pl?')[1]` is not be so you'll see an "undefined does not have method match" error.

QA plan should be:

1. Navigate to circ/circulation.pl?borrowernumber=X
2. See the console error `document.referrer.split(...)[1] is undefined`
3. Go to circ home circ/circulation-home.pl and search for a patron
4. See the console error when you select a patron or are taken directly to them
5. APPLY PATCH
6. JS error should be gone in both instances
Comment 7 Eric Phetteplace 2025-03-25 17:21:08 UTC
This code works since it checks the split array index first before using match:

if (document.referrer.length) {
    const referrerSplit = document.referrer.split(window.location.origin + '/cgi-bin/koha/cataloguing/additem.pl?')
    if(referrerSplit[1] && referrerSplit[1].match(/frameworkcode=FA&circborrowernumber=/) ) {
        let urlParams = new URLSearchParams(window.location.search);
        let barcode = urlParams.get('barcode');
        $('#barcode').val(barcode);
        $('#mainform').submit();
    }
}

Happy to make a patch and apologies if it's uncouth to set back to failed QA without consulting anyone. I just noticed this console error on our instance and saw that it wasn't due to referrer being undefined but due to the problem I stated above.
Comment 8 Brendan Lawlor 2025-03-25 18:31:46 UTC
Hi Eric, thanks for catching this and changing to Failed QA. I apologize for not testing thoroughly enough.

Your explanation, test plan and code makes sense. If you submit a patch I can test and sign off.
Comment 9 Eric Phetteplace 2025-03-25 19:18:38 UTC
Created attachment 179701 [details] [review]
Bug 39307: Check to make sure there is a document.referrer

To test:
1. Navigate to circ/circulation.pl?borrowernumber=X
2. See the console error `document.referrer.split(...)[1] is undefined`
3. Go to circ home circ/circulation-home.pl and search for a patron
4. See the console error when you select a patron or are taken directly to them
5. APPLY PATCH
5. JS error should be gone in both instances
Comment 10 Lucas Gass (lukeg) 2025-03-25 19:50:58 UTC
Created attachment 179702 [details] [review]
Bug 39307: Check to make sure there is a document.referrer

To test:
1. Navigate to circ/circulation.pl?borrowernumber=X
2. See the console error `document.referrer.split(...)[1] is undefined`
3. Go to circ home circ/circulation-home.pl and search for a patron
4. See the console error when you select a patron or are taken directly to them
5. APPLY PATCH
5. JS error should be gone in both instances

squash

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 11 Brendan Lawlor 2025-03-25 20:48:05 UTC
Created attachment 179707 [details] [review]
Bug 39307: Check to make sure there is a document.referrer

To test:
1. Navigate to circ/circulation.pl?borrowernumber=X
2. See the console error `document.referrer.split(...)[1] is undefined`
3. Go to circ home circ/circulation-home.pl and search for a patron
4. See the console error when you select a patron or are taken directly to them
5. APPLY PATCH
5. JS error should be gone in both instances

squash

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Comment 12 Katrin Fischer 2025-04-11 07:56:08 UTC
Pushed for 25.05!

Well done everyone, thank you!
Comment 13 Fridolin Somers 2025-06-30 09:48:17 UTC
Pushed to 24.11.x for 24.11.07