diff options
author | Alexis Hildebrandt <afh@surryhill.net> | 2015-01-20 21:53:44 +0100 |
---|---|---|
committer | Alexis Hildebrandt <afh@surryhill.net> | 2015-01-20 22:18:32 +0100 |
commit | 17189b81062b78baf4da1cf1ee494dc66bf1f736 (patch) | |
tree | 7e11da7cee1bfc35f82b7c966f62ec4e840bcf81 | |
parent | 4ec3c9382918bce74fed02c1a5d001c0b8553140 (diff) | |
download | fork-ledger-17189b81062b78baf4da1cf1ee494dc66bf1f736.tar.gz fork-ledger-17189b81062b78baf4da1cf1ee494dc66bf1f736.tar.bz2 fork-ledger-17189b81062b78baf4da1cf1ee494dc66bf1f736.zip |
[fix] Make trim function trim trailing whitespace
std::isspace(*e) returns false for the end of c-string null-byte.
Bugzilla: 1106
-rw-r--r-- | src/report.cc | 4 | ||||
-rw-r--r-- | test/regress/1106.test | 11 |
2 files changed, 13 insertions, 2 deletions
diff --git a/src/report.cc b/src/report.cc index 4b240611..2ce70151 100644 --- a/src/report.cc +++ b/src/report.cc @@ -631,7 +631,7 @@ value_t report_t::fn_trim(call_scope_t& args) while (*p && std::isspace(*p)) p++; - const char * e = buf.get() + temp.length(); + const char * e = buf.get() + temp.length() - 1; while (e > p && std::isspace(*e)) e--; @@ -643,7 +643,7 @@ value_t report_t::fn_trim(call_scope_t& args) return string_value(empty_string); } else { - return string_value(string(p, static_cast<std::string::size_type>(e - p))); + return string_value(string(p, static_cast<std::string::size_type>(e - p + 1))); } } diff --git a/test/regress/1106.test b/test/regress/1106.test new file mode 100644 index 00000000..c6b41071 --- /dev/null +++ b/test/regress/1106.test @@ -0,0 +1,11 @@ +2015/01/20 Payee + Assets:Cash ¤ 12,34 + Expenses:Food + +test -F "»%(trim(' Trimmed '))«\n" reg expenses +»Trimmed« +end test + +test -F "»%(trim('Trimmed'))«\n" reg expenses +»Trimmed« +end test |