Bug 23045: TextMarc errors on blank lines
authorNick Clemens <nick@bywatersolutions.com>
Tue, 4 Jun 2019 14:25:53 +0000 (14:25 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 1 Jul 2019 13:52:37 +0000 (14:52 +0100)
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 <claire.gravely@bsz-bw.de>
Signed-off-by: Liz Rea <wizzyrea@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

koha-tmpl/intranet-tmpl/lib/koha/cateditor/text-marc.js
koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc

index 0440a99..5846045 100644 (file)
@@ -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;
index 3c4594f..ab5e655 100644 (file)
@@ -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];