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

Additional patch for #1279 #1282

Merged
merged 2 commits into from
Sep 12, 2013
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class JSONPAtmosphereInterceptor extends AtmosphereInterceptorAdapter {

@Override
public Action inspect(AtmosphereResource r) {

final AtmosphereRequest request = r.getRequest();
final AtmosphereResponse response = r.getResponse();
if (r.transport().equals(AtmosphereResource.TRANSPORT.JSONP)) {
Expand Down Expand Up @@ -82,7 +81,10 @@ public byte[] transformPayload(AtmosphereResponse response, byte[] responseDraft
String charEncoding = response.getCharacterEncoding() == null ? "UTF-8" : response.getCharacterEncoding();
// TODO: TOTALLY INEFFICIENT. We MUST uses binary replacement instead.
String s = new String(responseDraft, charEncoding);
return s.replace("\"", "\\\"").getBytes(charEncoding);
return s.replaceAll("(['\"\\/])", "\\\\$1")
.replaceAll("\b", "\\\\b").replaceAll("\n", "\\\\n")
.replaceAll("\t", "\\\\t").replaceAll("\f", "\\\\f")
.replaceAll("\r", "\\\\r").getBytes(charEncoding);
}
return responseDraft;
}
Expand Down