Skip to content

Commit 04a3e11

Browse files
committed
do not trim strings containing line breaks
1 parent 2948d79 commit 04a3e11

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/SapRfcFunction.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ public function __destruct()
5757
protected function execute()
5858
{
5959
try {
60-
return $this->function->invoke($this->params);
60+
$result = $this->function->invoke($this->params);
6161
} catch (\Exception $exception) {
6262
throw new FunctionCallException(sprintf(
6363
'Function call %s failed: %s',
6464
$this->getName(),
6565
$exception->getMessage()
6666
), 0, $exception);
6767
}
68+
return $this->trimStrings($result);
6869
}
6970

7071
/**
@@ -84,4 +85,28 @@ protected function getFunction()
8485
), 0, $exception);
8586
}
8687
}
88+
89+
/**
90+
* Trim the strings of a given data structure.
91+
* @param mixed $return
92+
* @return mixed
93+
*/
94+
protected function trimStrings($return)
95+
{
96+
if (is_string($return)) {
97+
/**
98+
* Do not trim strings containing line breaks.
99+
*/
100+
if (strtr($return, "\n") || strtr($return, "\r\n")) {
101+
return $return;
102+
}
103+
return rtrim($return);
104+
}
105+
if (is_array($return)) {
106+
foreach ($return as $key => $value) {
107+
$return[$key] = $this->trimStrings($value);
108+
}
109+
}
110+
return $return;
111+
}
87112
}

0 commit comments

Comments
 (0)