[freeside-commits] branch FREESIDE_3_BRANCH updated. 1c31e0c4990be38568f6a73cfaeede4d9fde387f

Ivan Kohler ivan at freeside.biz
Mon May 23 15:06:38 PDT 2022


The branch, FREESIDE_3_BRANCH has been updated
       via  1c31e0c4990be38568f6a73cfaeede4d9fde387f (commit)
      from  c57b1c37752141c6c1ab4e96382f03e8a2c9f9a0 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 1c31e0c4990be38568f6a73cfaeede4d9fde387f
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Mon May 23 15:06:37 2022 -0700

    properly deal with broadsoft's awful non-standard quoting, RT#86028, RT#81941

diff --git a/FS/FS/cdr/broadsoft.pm b/FS/FS/cdr/broadsoft.pm
index 01755a8bf..ab4815095 100644
--- a/FS/FS/cdr/broadsoft.pm
+++ b/FS/FS/cdr/broadsoft.pm
@@ -23,12 +23,17 @@ use FS::cdr qw( _cdr_date_parser_maker _cdr_min_parser_maker );
   sep_char => ',',
   disabled => 0,
 
+  #deal with broadsoft's awful non-standard CSV escaping :/
   row_callback => sub {
     my $line = shift;
-    #try to deal with broadsoft's awful non-standard CSV escaping :/
-    $line =~ s/\\,/ /g;  # \, becomes just a space... not entirely accurate,
-                          #  but better than skewing data into the wrong fields
-    $line =~ s/\\\\/\\/g; # undo double backslashes?  none in my test data
+    $line = qq("$line");       # put " at the beginning and end
+    $line =~ s/(?<!\\),/","/g; # all commas not after a \ become ","
+    $line =~ s/\\,/,/g;        # and now we can turn \, into ,
+    #XXX embedded \r and \n ?  none in my test data, and might be better to 
+    # leave escaped and deal with it from there?
+    $line =~ s/\\\\/\\/g;     # undo double backslashes?  none in my test data
+
+    #and now we have a properly formed CSV line
     $line;
   },
 

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/cdr/broadsoft.pm | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)




More information about the freeside-commits mailing list