Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(648)

Unified Diff: frog/server/dart_json.dart

Issue 9181003: Fix to the JsonStringifier in dart_json.dart to escape eols. The error messages that frog sends t... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « client/tests/client/json/json_tests.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/server/dart_json.dart
===================================================================
--- frog/server/dart_json.dart (revision 3253)
+++ frog/server/dart_json.dart (working copy)
@@ -137,6 +137,8 @@
static final int A_SMALL = 97; // 'a'.charCodeAt(0)
static final int B_SMALL = 98; // 'b'.charCodeAt(0)
static final int E_SMALL = 101; // 'e'.charCodeAt(0)
+ static final int N_SMALL = 110; // 'n'.charCodeAt(0)
+ static final int R_SMALL = 114; // 'r'.charCodeAt(0)
static final int Z_SMALL = 122; // 'z'.charCodeAt(0)
static final int LBRACE = 123; // '{'.charCodeAt(0)
static final int RBRACE = 125; // '}'.charCodeAt(0)
@@ -496,7 +498,8 @@
// TODO: add others.
static bool _needsEscape(int charCode) {
- return JsonTokenizer.QUOTE == charCode || JsonTokenizer.BACKSLASH == charCode;
+ return JsonTokenizer.QUOTE == charCode || JsonTokenizer.BACKSLASH == charCode
+ || JsonTokenizer.NEW_LINE == charCode || JsonTokenizer.LINE_FEED == charCode;
}
static void _escape(StringBuffer sb, String s) {
@@ -507,10 +510,16 @@
bool needsEscape = false;
final charCodes = new List<int>();
for (int i = 0; i < length; i++) {
- final int charCode = s.charCodeAt(i);
+ int charCode = s.charCodeAt(i);
if (_needsEscape(charCode)) {
charCodes.add(JsonTokenizer.BACKSLASH);
needsEscape = true;
+
+ if (JsonTokenizer.NEW_LINE == charCode) {
+ charCode = N_SMALL;
+ } else if (JsonTokenizer.LINE_FEED == charCode) {
+ charCode = R_SMALL;
+ }
}
charCodes.add(charCode);
}
« no previous file with comments | « client/tests/client/json/json_tests.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698