From ca99bfd7e8ee7b11f63d78fdea312665f8f7f6e9 Mon Sep 17 00:00:00 2001 From: Jesse Weaver Date: Fri, 23 Oct 2015 11:06:39 -0600 Subject: [PATCH] Bug 11559: (QA followup) detect and warn about corruption caused by MARC-8 Signed-off-by: Katrin Fischer --- .../intranet-tmpl/lib/koha/cateditor/marc-record.js | 11 +++++++++++ .../intranet-tmpl/prog/en/includes/cateditor-ui.inc | 2 ++ 2 files changed, 13 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/marc-record.js b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/marc-record.js index f626eb39a9..d795511f24 100644 --- a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/marc-record.js +++ b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/marc-record.js @@ -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 { diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc index 4cc594fb61..fe792c0962 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc @@ -909,6 +909,8 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr return; } + if (record.marc8_corrupted) humanMsg.displayMsg( '

' + _("Possible record corruption") + '

' + _("Record not marked as UTF-8, may be corrupted") + '

', { className: 'humanError' } ); + editor.displayRecord( record ); }; -- 2.39.5