Merge pull request #521 from mbudde/fix-trim

Fix handling of edge cases in trim function
This commit is contained in:
Alexis Hildebrandt 2018-01-27 15:55:08 +08:00 committed by GitHub
commit 1be23f1653
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 7 deletions

View file

@ -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 {

33
test/regress/GH520.test Normal file
View file

@ -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