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

Side by Side Diff: Source/devtools/front_end/network/RequestJSONView.js

Issue 1163523002: DevTools: remove hand-written optimistic JSON parser introduced in r183821. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: bringing relaxed parser back Created 5 years, 6 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 unified diff | Download patch
« no previous file with comments | « LayoutTests/http/tests/inspector/network/network-preview-json-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 129 }
130 return (result.length > 1) ? result : result[0]; 130 return (result.length > 1) ? result : result[0];
131 } 131 }
132 132
133 /** 133 /**
134 * @param {string} text 134 * @param {string} text
135 * @return {?WebInspector.ParsedJSON} 135 * @return {?WebInspector.ParsedJSON}
136 */ 136 */
137 WebInspector.RequestJSONView.parseJSON = function(text) 137 WebInspector.RequestJSONView.parseJSON = function(text)
138 { 138 {
139 // Trim stubs like "while(1)", "for(;;)", weird numbers, etc. We need JSON s tart. 139 // Do not treat HTML as JSON.
140 if (text.startsWith("<"))
141 return null;
140 var inner = WebInspector.RequestJSONView._findBrackets(text, "{", "}"); 142 var inner = WebInspector.RequestJSONView._findBrackets(text, "{", "}");
141 var inner2 = WebInspector.RequestJSONView._findBrackets(text, "[", "]"); 143 var inner2 = WebInspector.RequestJSONView._findBrackets(text, "[", "]");
142 inner = inner2.length > inner.length ? inner2 : inner; 144 inner = inner2.length > inner.length ? inner2 : inner;
143 var inner3 = WebInspector.RequestJSONView._findBrackets(text, "(", ")"); 145
144 if (inner3.length - 2 > inner.length) { 146 // Return on blank payloads or on payloads significantly smaller than origin al text.
145 inner = inner3; 147 if (inner.length === -1 || text.length - inner.length > 80)
146 ++inner.start;
147 --inner.end;
148 }
149 if (inner.length === -1)
150 return null; 148 return null;
151 149
152
153 var prefix = text.substring(0, inner.start); 150 var prefix = text.substring(0, inner.start);
154 var suffix = text.substring(inner.end + 1); 151 var suffix = text.substring(inner.end + 1);
155 text = text.substring(inner.start, inner.end + 1); 152 text = text.substring(inner.start, inner.end + 1);
156 153
154 // Only process valid JSONP.
155 if (suffix.length && !(suffix.trim().startsWith(")") && prefix.trim().endsWi th("(")))
156 return null;
157
157 try { 158 try {
158 return new WebInspector.ParsedJSON(WebInspector.RequestJSONView._buildOb jectFromJSON(text), prefix, suffix); 159 return new WebInspector.ParsedJSON(WebInspector.RequestJSONView._buildOb jectFromJSON(text), prefix, suffix);
159 } catch (e) { 160 } catch (e) {
160 return null; 161 return null;
161 } 162 }
162 } 163 }
163 164
164 /** 165 /**
165 * @param {string} text 166 * @param {string} text
166 * @param {string} open 167 * @param {string} open
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 203
203 /** 204 /**
204 * @constructor 205 * @constructor
205 */ 206 */
206 WebInspector.ParsedJSON = function(data, prefix, suffix) 207 WebInspector.ParsedJSON = function(data, prefix, suffix)
207 { 208 {
208 this.data = data; 209 this.data = data;
209 this.prefix = prefix; 210 this.prefix = prefix;
210 this.suffix = suffix; 211 this.suffix = suffix;
211 } 212 }
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/inspector/network/network-preview-json-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698