From 8b3e00174b2ef5643e559873fb4215b9e3fec29a 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 Signed-off-by: Liz Rea Signed-off-by: Martin Renvoize (cherry picked from commit 545f38d13c210e4cb173e67d2578d825a9ffeb47) Signed-off-by: Fridolin Somers (cherry picked from commit 2340df6f7c85c48a2ae68292204e9f16d485e7b9) Signed-off-by: Lucas Gass --- koha-tmpl/intranet-tmpl/lib/koha/cateditor/text-marc.js | 3 +-- .../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 0440a99822..5846045bb7 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 3c4594f7ff..ab5e655080 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.39.5