|go ahead... be a heretic|
Beware of the newline at the end of the encode_base64() encoded stringsby kirillm (Friar)
|on Jan 04, 2008 at 16:06 UTC||Need Help??|
Just some friday thoughts I'd like to share.
There's a line oriented network protocol where each command ends with a newline character. One of the commands there uses base64 encoded string as it's last argument.
On another side there's a client. It's written in Perl and it wasn't written by me. And it started misbehaving when an additional parameter was added after the one that was base64 encoded. The troubles were caused by a newline...
The client produced base64 data with encode_base64() from MIME::Base64 like this:
This seems perfectly fine. Later these data were sent to the server:
This also seems perfectly fine. Now a new parameter was added:
The new parameter was ignored by the server when it processed the command and seeing what was wrong was not easy. Finally debugging at the server side showed that the client sent the new argument as a command by itself. This was very strange. Then I thought that maybe a newline somehow came between base64 data and the new argument... Reading the docs revealed that encode_base64() by default returns the data with a newline at the end!
The fix was easy.
Beware of that newline and have a happy week end!