Bugzilla – Attachment 157628 Details for
Bug 35104
We should warn when attempting to save MARC records that contain characters invalid in XML
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35104: Alert when inserting text invalid in XML into bib record
Bug-35104-Alert-when-inserting-text-invalid-in-XML.patch (text/plain), 3.74 KB, created by
David Cook
on 2023-10-23 04:56:37 UTC
(
hide
)
Description:
Bug 35104: Alert when inserting text invalid in XML into bib record
Filename:
MIME Type:
Creator:
David Cook
Created:
2023-10-23 04:56:37 UTC
Size:
3.74 KB
patch
obsolete
>From db21aef412a7eb4995c685263042093194d9626a Mon Sep 17 00:00:00 2001 >From: David Cook <dcook@prosentient.com.au> >Date: Mon, 23 Oct 2023 02:01:03 +0000 >Subject: [PATCH] Bug 35104: Alert when inserting text invalid in XML into bib > record > >This change adds a Javascript based alert when a user tries to save >data via the bib record editor that is invalid in XML. > >Test plan: >0. Apply patch >1. Go to http://localhost:8081/cgi-bin/koha/cataloguing/addbiblio.pl?frameworkcode= >2. Copy the data from "Text file containing control characters" >3. Paste the data into 245$a and 500$a >4. Click "Save" >5. Note the alerts at the top of the web page and that the record does not save >6. Resolve the problems >7. Click "Save" >8. Note that the record saves >--- > .../prog/en/modules/cataloguing/addbiblio.tt | 50 +++++++++++++++++++ > 1 file changed, 50 insertions(+) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt >index 6d7b255c84..bd640b92a9 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt >@@ -726,6 +726,45 @@ $(document).ready(function(){ > } > } > >+ function containsInvalidXMLChars(input) { >+ let pattern = /[^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u10000-\u10FFFF]+/; >+ return pattern . test(input); >+ } >+ >+ function checkForXML(){ >+ let alert_text = ""; >+ let subfields = new Array(); >+ const regex = /([A-Za-z0-9]+)_subfield_([A-Za-z0-9]+)_/; >+ $("input[type='text'].input_marceditor, textarea.input_marceditor").each(function(){ >+ if ( containsInvalidXMLChars(this.value) ){ >+ let html_id = this.id; >+ let subfield = { "id": html_id }; >+ //FIXME: Turns out tabindex isn't the real tab index... >+ subfield['tab'] = parseInt(this.getAttribute('tabindex')) + 1; >+ let match = html_id.match(regex); >+ if (match){ >+ subfield['tag'] = match[1]; >+ subfield['subfield_code'] = match[2]; >+ } >+ subfields.push(subfield); >+ } >+ }); >+ if (subfields.length > 0){ >+ alert_text += "<div class='dialog alert list'>"; >+ alert_text += "<h4>" + _("The following subfields contain characters invalid in XML:") + "</h4>"; >+ for (let i = 0; i < subfields.length; i++){ >+ let subfield = subfields[i]; >+ let tag = subfield.tag; >+ let subfield_code = subfield.subfield_code; >+ let tab = subfield.tab; >+ let id = subfield.id; >+ alert_text += "<li>"+_("Tag %s subfield %s in tab %s").format(tag, subfield_code, tab) + ' <a class="linkfield btn btn-link" href="#" data-tab="' + tab + '" data-field="' + id + '"><i class="fa fa-arrow-right" aria-hidden="true"></i> ' + _("Go to field") + '</a></li>'; >+ } >+ alert_text += "</div>"; >+ } >+ return alert_text; >+ } >+ > /** > * Run checks for mandatory and important fields > * Output errors if necessary, or submit the form >@@ -733,6 +772,17 @@ $(document).ready(function(){ > function Check(){ > var StrAlert = AreFieldsNotOk(); > var StrWarning = AreFieldsNotOk( false ); >+ >+ [% IF ! advancedMARCEditor %] >+ let AlertXML = checkForXML(); >+ if (AlertXML) { >+ if ( StrAlert === false ) { >+ StrAlert = ''; >+ } >+ StrAlert += AlertXML; >+ } >+ [% END %] >+ > if( !StrAlert && StrWarning ){ > // Check important fields > $("#check_errors").html( StrWarning ); >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35104
:
157625
|
157627
|
157628
|
157642
|
159615
|
159620
|
159621
|
159630
|
159810
|
159811
|
159812
|
159813
|
166431
|
173145
|
173146