voloko / twitter-stream

Twitter realtime API client
MIT License
233 stars 81 forks source link

Doesn't handle messages split over multiple lines #42

Open timhaines opened 9 years ago

timhaines commented 9 years ago

Using sitestreams, sometimes messages are split over multiple lines (possibly in userstreams too - I don't know?).

There's a few changes that need to be made to handle split lines with this library, but I wanted to point out a non-obvious one.

If a message is split, the split can be anywhere in the message content. Sometimes this means a space from the message is at the start or end of a split line.

The parse_stream_line method starts out by calling ln.strip! with the intention of removing the leading newline. This is problematic, as it also removes the leading or trailing space when they should be there in split lines, causing data corruption.

Changing ln.strip! to ln[0] = '' resolves the issue - but you probably also want to update later checks for ln.empty? as the heartbeat signals from Twitter will now look like "\n" instead of being empty strings (or something similar to this..).