summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2022-05-23 15:06:31 -0700
committerIvan Kohler <ivan@freeside.biz>2022-05-23 15:06:31 -0700
commit2c7c526d0485fbd2eaf59b54ff5fe7a1d4e01970 (patch)
tree39182dfbfd9735b81cebf9da5c5365dbb925a7d9 /FS
parent876a95ece211ff6478a609f5e99109957f66e477 (diff)
properly deal with broadsoft's awful non-standard quoting, RT#86028, RT#81941
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/cdr/broadsoft.pm13
1 files changed, 9 insertions, 4 deletions
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;
},