From 9a270ef9470db7ca110c2ad60fcd13f8674fdf63 Mon Sep 17 00:00:00 2001 From: Charles McGarvey Date: Sat, 17 Aug 2019 15:35:38 -0600 Subject: [PATCH 1/1] support quoting commodity symbols --- lib/App/HomeBank2Ledger/Formatter/Ledger.pm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/App/HomeBank2Ledger/Formatter/Ledger.pm b/lib/App/HomeBank2Ledger/Formatter/Ledger.pm index 677facb..71d9020 100644 --- a/lib/App/HomeBank2Ledger/Formatter/Ledger.pm +++ b/lib/App/HomeBank2Ledger/Formatter/Ledger.pm @@ -269,6 +269,13 @@ sub _format_string { return $str; } +sub _quote_string { + my $self = shift; + my $str = shift; + $str =~ s/"/\\"/g; + return "\"$str\""; +} + sub _format_amount { my $self = shift; my $amount = shift; @@ -279,7 +286,10 @@ sub _format_amount { my $num = join($commodity->{dchar}, commify($whole, $commodity->{gchar}), $fraction); - $num = $commodity->{syprf} ? "$commodity->{symbol} $num" : "$num $commodity->{symbol}"; + my $symbol = $commodity->{symbol}; + $symbol = $self->_quote_string($symbol) if $symbol =~ /[0-9\s]/; + + $num = $commodity->{syprf} ? "$symbol $num" : "$num $symbol"; return $num; } -- 2.43.0