diff options
-rw-r--r-- | src/report.cc | 11 | ||||
-rw-r--r-- | test/regress/GH520.test | 33 |
2 files changed, 37 insertions, 7 deletions
diff --git a/src/report.cc b/src/report.cc index 44f0c4b9..cb7f09dc 100644 --- a/src/report.cc +++ b/src/report.cc @@ -633,18 +633,15 @@ value_t report_t::fn_trim(call_scope_t& args) std::strcpy(buf.get(), temp.c_str()); const char * p = buf.get(); - while (*p && std::isspace(*p)) + const char * e = buf.get() + temp.length() - 1; + + while (p <= e && std::isspace(*p)) p++; - const char * e = buf.get() + temp.length() - 1; while (e > p && std::isspace(*e)) e--; - if (e == p) { - return string_value(empty_string); - } - else if (e < p) { - assert(false); + if (p > e) { return string_value(empty_string); } else { diff --git a/test/regress/GH520.test b/test/regress/GH520.test new file mode 100644 index 00000000..54dd2299 --- /dev/null +++ b/test/regress/GH520.test @@ -0,0 +1,33 @@ +2009-01-01 * Jan 09 + A 100.00 EUR + B + +test reg --format '%(trim(""))\n' + + +end test + +test reg --format '%(trim("a"))\n' +a +a +end test + +test reg --format '%(trim(" a"))\n' +a +a +end test + +test reg --format '%(trim("a "))\n' +a +a +end test + +test reg --format '%(trim(" a "))\n' +a +a +end test + +test reg --format '%(trim(" aa "))\n' +aa +aa +end test |