From: Erik Bernhardson Date: Fri, 28 Sep 2018 17:58:00 +0000 (-0700) Subject: Only strip newline in OrderedStreamingForkController X-Git-Tag: 1.34.0-rc.0~3967 X-Git-Url: http://git.cyclocoop.org/url?a=commitdiff_plain;h=c94dea7029caea6377f4e36213104afde0bd6642;p=lhc%2Fweb%2Fwiklou.git Only strip newline in OrderedStreamingForkController The controller should pass through lines of input exactly as they were provided, only stripping the trailing newline that delimits items. The trim was making `door` and `door ` equivilant but for the use case in search the distinction is important. Additionally check that the line is actually empty, don't throw away inputs like '0' which are falsy. Change-Id: Ifac910543fdb46a27da021e831e3e18befefcfc5 --- diff --git a/includes/OrderedStreamingForkController.php b/includes/OrderedStreamingForkController.php index ff29cb510d..11abc81c1f 100644 --- a/includes/OrderedStreamingForkController.php +++ b/includes/OrderedStreamingForkController.php @@ -134,9 +134,12 @@ class OrderedStreamingForkController extends ForkController { */ protected function consumeNoFork() { while ( !feof( $this->input ) ) { - $line = trim( fgets( $this->input ) ); - if ( $line ) { - $result = call_user_func( $this->workCallback, $line ); + $data = fgets( $this->input ); + if ( $data[ strlen( $data ) - 1 ] == "\n" ) { + $data = substr( $data, 0, -1 ); + } + if ( strlen( $data ) !== 0 ) { + $result = call_user_func( $this->workCallback, $data ); fwrite( $this->output, "$result\n" ); } } @@ -160,8 +163,12 @@ class OrderedStreamingForkController extends ForkController { $this->updateAvailableSockets( $sockets, $used, $sockets ? 0 : 5 ); } while ( !$sockets ); } - $data = trim( $data ); - if ( !$data ) { + // Strip the trailing \n. The last line of a file might not have a trailing + // \n though + if ( $data[ strlen( $data ) - 1 ] == "\n" ) { + $data = substr( $data, 0, -1 ); + } + if ( strlen( $data ) === 0 ) { continue; } $socket = array_pop( $sockets );