From ee3bc82360bf78a73b6a166cfe8e539e32fa24af Mon Sep 17 00:00:00 2001
From: Xavier Robin <xavalias-github@xavier.robin.name>
Date: Thu, 1 Jun 2023 16:59:31 +0200
Subject: [PATCH] fix: permit trailing blank space in bonds block

---
 modules/io/src/mol/sdf_reader.cc | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/modules/io/src/mol/sdf_reader.cc b/modules/io/src/mol/sdf_reader.cc
index 2db564c66..ec84d1a01 100644
--- a/modules/io/src/mol/sdf_reader.cc
+++ b/modules/io/src/mol/sdf_reader.cc
@@ -253,9 +253,15 @@ void SDFReader::ParseAndAddBond(const String& line, int line_num,
   LOG_TRACE( "line: [" << line << "]" );
 
   if(line.length()<9 || line.length()>21) {
-    String msg="Bad bond line %d: Not correct number of characters on the"
-               " line: %i (should be between 9 and 21)";
-    throw IOException(str(format(msg) % line_num % line.length()));
+    // Handle the case where we have trailing space characters
+    if (line.length()>21 && boost::trim_copy(line.substr(21)) == "") {
+      LOG_ERROR( "Ignoring trailing space" );
+    }
+    else {
+      String msg="Bad bond line %d: Not correct number of characters on the"
+                 " line: %i (should be between 9 and 21)";
+      throw IOException(str(format(msg) % line_num % line.length()));
+    }
   }
 
   String s_first_name=line.substr(0,3);
-- 
GitLab