From 6821102bb11f949f440c25b5197fc56271bd49bf Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 4 Jun 2019 14:25:53 +0000 Subject: [PATCH] Bug 23045: TextMarc errors on blank lines Since bug 16251 we use TextMarc to get some record fields, however, it throws an error when processing blank lines. We should just pass on these rather then erroring To test: 1 - Define a new macro that delete more fields than it adds delete 245 2 - Run it 3 - Note an error in JS console, and helpers will not load 4 - Apply patch 5 - Reload, try again 6 - No error Signed-off-by: Claire Gravely --- koha-tmpl/intranet-tmpl/lib/koha/cateditor/text-marc.js | 3 +-- koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/text-marc.js b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/text-marc.js index 0440a99..5846045 100644 --- a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/text-marc.js +++ b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/text-marc.js @@ -48,10 +48,9 @@ define( [ 'marc-record' ], function( MARC ) { TextToRecord: function( text ) { var record = new MARC.Record(); var errors = []; - $.each( text.split('\n'), function( i, line ) { + if (line === "") {return}; var tagNumber = line.match( /^([A-Za-z0-9]{3}) / ); - if ( !tagNumber ) { errors.push( { type: 'noTag', line: i } ); return; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc index 3c4594f..ab5e655 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc @@ -282,6 +282,7 @@ require( [ 'koha-backend', 'widget', 'text-marc' ], function( KohaBackend, Widge }, getMaterial: function () { const record = TextMarc.TextToRecord(this.editor.cm.getValue()); + const leader = record.leader(); const leader6 = leader.substring(6, 7); let materialType = this.materialTypeMapping[leader6]; -- 2.1.4