Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
("Some data might be lost when junk comments are mixed with streaming data")

See issue description
  • Loading branch information
jfarcand committed Sep 29, 2010
1 parent fe5e244 commit f1f8ea9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Expand Up @@ -351,7 +351,7 @@ public static String createCompatibleStringJunk() {
StringBuilder s = new StringBuilder();

s.append("<!-- ----------------------------------------------------------" +
"---------------------------------------------------------------" +
"------ http://github.com/Atmosphere ----------------------------" +
"-------------------------------------------- -->\n");
s.append("<!-- Welcome to the Atmosphere Framework. To work with all the" +
" browsers when suspending connection, Atmosphere must output some" +
Expand All @@ -361,6 +361,7 @@ public static String createCompatibleStringJunk() {
"---------------------------------------------------------------" +
"-------------------------------------------- -->\n");
}
s.append("<!-- EOD -->");
return s.toString();
}

Expand Down
18 changes: 13 additions & 5 deletions modules/jquery/src/main/webapp/jquery/jquery.atmosphere.js
Expand Up @@ -201,11 +201,19 @@ jQuery.atmosphere = function()
if (update) {
if (request.transport == 'streaming') {
response.responseBody = ajaxRequest.responseText.substring(request.lastIndex, ajaxRequest.responseText.length);
request.lastIndex = ajaxRequest.responseText.length;

if (response.responseBody.indexOf("<!--") != -1) {
junkForWebkit = true;
if (request.lastIndex == 0 && response.responseBody.indexOf("<!-- Welcome to the Atmosphere Framework.") != -1) {
var endOfJunk = "<!-- EOD -->";
var endOfJunkLenght = "<!-- EOD -->".length;
var junkEnd = response.responseBody.indexOf(endOfJunk) + endOfJunkLenght;

if (junkEnd != ajaxRequest.responseText.length) {
response.responseBody = response.responseBody.substring(junkEnd);
} else {
junkForWebkit = true;
}
}
request.lastIndex = ajaxRequest.responseText.length;

} else {
response.responseBody = ajaxRequest.responseText;
Expand All @@ -217,8 +225,6 @@ jQuery.atmosphere = function()
response.responseBody = response.responseBody.substring(start, end);
}

if (junkForWebkit) return;

try {
response.status = ajaxRequest.status;
response.headers = ajaxRequest.getAllResponseHeaders();
Expand All @@ -232,6 +238,8 @@ jQuery.atmosphere = function()
} else {
response.state = "messagePublished";
}

if (junkForWebkit) return;
jQuery.atmosphere.invokeCallback(response);
}
}
Expand Down

0 comments on commit f1f8ea9

Please sign in to comment.