mpetazzoni/sse.js

If steam message content contains \n will lost content

tomtrije opened this issue · 6 comments

likes title describle

Bug is here:


chunk.split(/\n|\r\n|\r/).forEach(function(line) {
      line = line.trimRight();
      var index = line.indexOf(this.FIELD_SEPARATOR);
      if (index <= 0) {
        // Line was either empty, or started with a separator and is a comment.
        // Either way, ignore.
        return;
      }

      var field = line.substring(0, index);
      if (!(field in e)) {
        return;
      }

      var value = line.substring(index + 1).trimLeft();
      if (field === 'data') {
        e[field] += value;
      } else {
        e[field] = value;
      }
    }.bind(this));

if chunk data likes this, will lost \n(which in line3 and line4) in "data" field

event:add
id:7753781597103745505
data:
data:
data:something

also trimRight and trimLeft will cause lost blank character

also trimRight and trimLeft will cause lost blank character

I just hit that problem in my implementation, I lost important blank spaces

@tomtrije You can try my changes from PR #35

my repo is at https://github.com/rodrigovr/sse.js/tree/main but I will close the fork as soon as the changes are accepted here

Merged #35. Thanks @rodrigovr !