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

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
Index: frog/server/dart_json.dart
===================================================================
--- frog/server/dart_json.dart (revision 3201)
+++ frog/server/dart_json.dart (working copy)
@@ -496,7 +496,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 +508,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 = 110; // 'n'
+ } else if (JsonTokenizer.LINE_FEED == charCode) {
+ charCode = 114; // 'r'
+ }
}
charCodes.add(charCode);
}
« client/tests/client/json/json_tests.dart ('K') | « 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