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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/network/RequestJSONView.js
diff --git a/Source/devtools/front_end/network/RequestJSONView.js b/Source/devtools/front_end/network/RequestJSONView.js
index 8373b078d6f7e4bb16d07b2c839f68acce01112a..f88c212c65b26a543efed8283159b744c12fbf42 100644
--- a/Source/devtools/front_end/network/RequestJSONView.js
+++ b/Source/devtools/front_end/network/RequestJSONView.js
@@ -136,24 +136,25 @@ WebInspector.RequestJSONView._buildObjectFromJSON = function(text)
*/
WebInspector.RequestJSONView.parseJSON = function(text)
{
- // Trim stubs like "while(1)", "for(;;)", weird numbers, etc. We need JSON start.
+ // Do not treat HTML as JSON.
+ if (text.startsWith("<"))
+ return null;
var inner = WebInspector.RequestJSONView._findBrackets(text, "{", "}");
var inner2 = WebInspector.RequestJSONView._findBrackets(text, "[", "]");
inner = inner2.length > inner.length ? inner2 : inner;
- var inner3 = WebInspector.RequestJSONView._findBrackets(text, "(", ")");
- if (inner3.length - 2 > inner.length) {
- inner = inner3;
- ++inner.start;
- --inner.end;
- }
- if (inner.length === -1)
- return null;
+ // Return on blank payloads or on payloads significantly smaller than original text.
+ if (inner.length === -1 || text.length - inner.length > 80)
+ return null;
var prefix = text.substring(0, inner.start);
var suffix = text.substring(inner.end + 1);
text = text.substring(inner.start, inner.end + 1);
+ // Only process valid JSONP.
+ if (suffix.length && !(suffix.trim().startsWith(")") && prefix.trim().endsWith("(")))
+ return null;
+
try {
return new WebInspector.ParsedJSON(WebInspector.RequestJSONView._buildObjectFromJSON(text), prefix, suffix);
} catch (e) {
« 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