Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blank lines parsing? #18

Closed
rngadam opened this issue Jan 11, 2013 · 4 comments
Closed

blank lines parsing? #18

rngadam opened this issue Jan 11, 2013 · 4 comments

Comments

@rngadam
Copy link

rngadam commented Jan 11, 2013

Trying to run a SSE server

https://github.com/tomkersten/sses-node-example

...that works with a browser against this module and I'm getting a parser error.

/home/rngadam/tradesparq/feynman/deps/sses-benchmark/node_modules/eventsource/lib/eventstream.js:58
    throw new Error(str);
          ^
Error: Parse error on line 1:
id: 1data: hello w
^
Expecting 'colon', 'char', 'space', got 'eol'
    at Object.parseError (/home/rngadam/tradesparq/feynman/deps/sses-benchmark/node_modules/eventsource/lib/eventstream.js:58:11)
    at Object.parse (/home/rngadam/tradesparq/feynman/deps/sses-benchmark/node_modules/eventsource/lib/eventstream.js:110:22)
    at Object.exports.parse (/home/rngadam/tradesparq/feynman/deps/sses-benchmark/node_modules/eventsource/lib/eventstream.js:363:56)
    at IncomingMessage.<anonymous> (/home/rngadam/tradesparq/feynman/deps/sses-benchmark/node_modules/eventsource/lib/eventsource.js:85:40)
    at IncomingMessage.EventEmitter.emit (events.js:88:17)
    at IncomingMessage._emitData (http.js:359:10)
    at HTTPParser.parserOnBody [as onBody] (http.js:123:21)
    at Socket.socketOnData [as ondata] (http.js:1366:20)
    at TCP.onread (net.js:403:27)

I think there might be a condition that is not taken into account by the parser:

http://www.w3.org/TR/2009/WD-eventsource-20091029/#event-stream-interpretation

If the line is empty (a blank line)
Dispatch the event, as defined below.

[...]

When the user agent is required to dispatch the event, then the user agent must act as follows:

If the data buffer is an empty string, set the data buffer and the event name buffer to the empty string and abort these steps.
aslakhellesoy added a commit that referenced this issue Jan 24, 2013
@aslakhellesoy
Copy link
Contributor

Can you post the entire text the parser fails to parse (with newlines)? I'm guessing it is something like this:

id: 1
data: hello world

And that parses just fine: 6b217bb

Not sure how to reproduce what you see...

@aslakhellesoy
Copy link
Contributor

I think I get it now. If you change the test I added to parse this instead: "\n\n\n\nid: 1\ndata: hello world\n\n" then I get:

Error: Parse error on line 1:
id: 1data: hell
^
Expecting 'colon', 'char', 'space', got 'eol'

So now it's at least reproducible...

@rngadam
Copy link
Author

rngadam commented Jan 25, 2013

It's always positive when the developer agrees with the tester ;). I tried modifying the parser to make it work but I'm rather a newbie at parsing and couldn't get it to work in the short time I tried.

@Fire-
Copy link
Contributor

Fire- commented Mar 20, 2013

This also appears to fail on UTF8 characters

Error: Parse error on line 2:
...uluren0724","body":"拜託這場一定要放youtube "}
-----------------------^
Expecting 'eol', 'colon', 'char', 'space', got 'INVALID'
Error: Parse error on line 2:
...k":"akasim","body":"沒錯 機體強弱不說"}
-----------------------^
Expecting 'eol', 'colon', 'char', 'space', got 'INVALID'
Error: Parse error on line 2:
...k":"d40301","body":"我現在都看實況不玩遊戲"}
-----------------------^
Expecting 'eol', 'colon', 'char', 'space', got 'INVALID'
Error: Parse error on line 2:
...panjimmy","body":"28沒人"}
-----------------------^
Expecting 'eol', 'colon', 'char', 'space', got 'INVALID'
Error: Parse error on line 2:
...zero751210","body":"西葛格晚上好wwwww"}
-----------------------^
Expecting 'eol', 'colon', 'char', 'space', got 'INVALID'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants