Bug 11559: (QA followup) detect and warn about corruption caused by MARC-8
authorJesse Weaver <pianohacker@gmail.com>
Fri, 23 Oct 2015 17:06:39 +0000 (11:06 -0600)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 27 Oct 2015 15:18:01 +0000 (12:18 -0300)
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
koha-tmpl/intranet-tmpl/lib/koha/cateditor/marc-record.js
koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc

index f626eb3..d795511 100644 (file)
@@ -244,6 +244,11 @@ define( function() {
             // happens before UTF-8 encoding, but that won't cause any issues.
             data = _encode_utf8(data.substr(0, parseInt(data.substr(0, 5))));
 
+            // For now, we can't decode MARC-8, so just mark the record as possibly corrupted.
+            if (data[9] != 'a') {
+                var marc8 = true;
+            }
+
             this._fieldlist.length = 0;
             this.leader(data.substr(0, 24));
             var directory_len = parseInt(data.substring(12, 17), 0) - 25,
@@ -254,6 +259,12 @@ define( function() {
                     len = parseInt(data.substring(off+3, off+7), 0) - 1,
                     pos = parseInt(data.substring(off+7, off+12), 0) + 25 + directory_len,
                     value = data.substring(pos, pos+len);
+
+                // No end-of-field character before this field, corruption!
+                if (marc8 && data[pos - 1] != '\x1E') {
+                    this.marc8_corrupted = true;
+                }
+
                 if ( parseInt(tag) < 10 ) {
                     this.addField( new MARC.Field( tag, '', '', [ [ '@', value ] ] ) );
                 } else {
index 4cc594f..fe792c0 100644 (file)
@@ -909,6 +909,8 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr
                             return;
                         }
 
+                        if (record.marc8_corrupted) humanMsg.displayMsg( '<h3>' + _("Possible record corruption") + '</h3><p>' + _("Record not marked as UTF-8, may be corrupted") + '</p>', { className: 'humanError' } );
+
                         editor.displayRecord( record );
                     };