Thread:Extension talk:Scribunto/Newline encoding

Posting it here, since someone may find it useful...

I had big problem with scripts that were returning texts containing a newline character ("\n") while running a test wiki in Windows environment. It was being displayed as "Script error" with "Lua error: Internal error: Unable to decode message." as description.

The problem is that while data passed to lua are being properly encoded, the ones that are returned are passed as raw data through textmode pipe, thus the "\n" was being encoded as "\r\n". In the end the php script didn't read all the transferred data, because there was one extra character in buffer for each newline character, desyncing whole communication in the process.

Managed to bypass the problem with small change in \engines\LuaStandalone\LuaStandaloneEngine.php

Lines 294-295 (the receiveMessage function) $body .= $buffer; $lengthRemaining -= strlen( $buffer ); were replaced with $buf1 = strtr($buffer, array("\r\n" => "\n")); $body .= $buf1; $lengthRemaining -= strlen( $buf1 );