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

Fix Unicode support to cope with Javascript Unicode size limitations #23

Merged
merged 1 commit into from
Apr 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/eventstream.jison
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
\u0020 return 'space';
":" return 'colon';
(\u000D\u000A|\u000D|\u000A) return 'eol';
[\u0000-\u0009\u000B-\u000C\u000E-\u0019\u0021-\u0039\u003B-\u10FFFF] return 'char';

/* Javascript can't support \u10FFFF , it's too large.
\uFFFFF is only 1 less and works correctly, size limitations! */

[\u0000-\u0009\u000B-\u000C\u000E-\u0019\u0021-\u0039\u003B-\uFFFFF] return 'char';

<<EOF>> return 'EOF';
. return 'INVALID';

Expand Down
28 changes: 14 additions & 14 deletions lib/eventstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) {

var $0 = $$.length - 1;
switch (yystate) {
case 1: return this.$;
case 1: return this.$;
break;
case 2: this.$ = $$[$0-2]; this.$.push($$[$0-1]);
case 2: this.$ = $$[$0-2]; this.$.push($$[$0-1]);
break;
case 3: this.$ = [$$[$0-1]];
case 3: this.$ = [$$[$0-1]];
break;
case 4:
this.$ = $$[$0-1];
Expand All @@ -22,7 +22,7 @@ case 4:
else if ($$[$0].name == 'event') this.$.event = $$[$0].value;
else if ($$[$0].name == 'id') this.$.id = $$[$0].value;
else if ($$[$0].name == 'retry') this.$.field = $$[$0].value;

break;
case 5:
this.$ = {
Expand All @@ -34,21 +34,21 @@ case 5:
else if ($$[$0].name == 'event') this.$.event = $$[$0].value;
else if ($$[$0].name == 'id') this.$.id = $$[$0].value;
else if ($$[$0].name == 'retry') this.$.field = $$[$0].value;

break;
case 8: this.$ = { name: 'comment', value: $$[$0] }
case 8: this.$ = { name: 'comment', value: $$[$0] }
break;
case 9: this.$ = { name: 'comment', value: '' }
case 9: this.$ = { name: 'comment', value: '' }
break;
case 10: this.$ = { name: $$[$0-3], value: $$[$0-1][0] === ' ' ? $$[$0-1].slice(1) : $$[$0-1] }
case 10: this.$ = { name: $$[$0-3], value: $$[$0-1][0] === ' ' ? $$[$0-1].slice(1) : $$[$0-1] }
break;
case 11: this.$ = { name: $$[$0-2], value: '' }
case 11: this.$ = { name: $$[$0-2], value: '' }
break;
case 12: this.$ = { name: $$[$0-1], value: '' }
case 12: this.$ = { name: $$[$0-1], value: '' }
break;
case 14: this.$ = $$[$0-1] + $$[$0];
case 14: this.$ = $$[$0-1] + $$[$0];
break;
case 16: this.$ = $$[$0-1] + $$[$0];
case 16: this.$ = $$[$0-1] + $$[$0];
break;
}
},
Expand Down Expand Up @@ -350,7 +350,7 @@ case 6:return 'INVALID';
break;
}
};
lexer.rules = [/^(?:^\uFEFF)/,/^(?:\u0020)/,/^(?::)/,/^(?:(\u000D\u000A|\u000D|\u000A))/,/^(?:[\u0000-\u0009\u000B-\u000C\u000E-\u0019\u0021-\u0039\u003B-\u10FFFF])/,/^(?:$)/,/^(?:.)/];
lexer.rules = [/^(?:^\uFEFF)/,/^(?:\u0020)/,/^(?::)/,/^(?:(\u000D\u000A|\u000D|\u000A))/,/^(?:[\u0000-\u0009\u000B-\u000C\u000E-\u0019\u0021-\u0039\u003B-\uFFFFF])/,/^(?:$)/,/^(?:.)/];
lexer.conditions = {"INITIAL":{"rules":[0,1,2,3,4,5,6],"inclusive":true}};
return lexer;})()
parser.lexer = lexer;
Expand All @@ -375,4 +375,4 @@ exports.main = function commonjsMain(args) {
if (typeof module !== 'undefined' && require.main === module) {
exports.main(typeof process !== 'undefined' ? process.argv.slice(1) : require("system").args);
}
}
}
11 changes: 11 additions & 0 deletions test/eventsource_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ exports['Messages'] = {
done();
},

'Multibyte Characters': function(test) {
createServer(["id: 1\ndata: €豆腐\n\n"], function(close) {
var es = new EventSource('http://localhost:' + port);
es.onmessage = function(m) {
test.equal("€豆腐", m.data);
es.close();
close(test.done);
};
});
},

'issue-18': function(test) {
createServer(["id: 1\ndata: hello world\n\n"], function(close) {
var es = new EventSource('http://localhost:' + port);
Expand Down