WebKit Bugzilla
Attachment 357851 Details for
Bug 192946
: Web Inspector: Autoformat doesn't work on icloud.com (javascript-packed.js)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
[PATCH] Proposed Fix
format-1.patch (text/plain), 6.34 KB, created by
Joseph Pecoraro
on 2018-12-20 12:46:30 PST
(
hide
)
Description:
[PATCH] Proposed Fix
Filename:
MIME Type:
Creator:
Joseph Pecoraro
Created:
2018-12-20 12:46:30 PST
Size:
6.34 KB
patch
obsolete
>diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index 9909214829b..37d7888b328 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,14 @@ >+2018-12-20 Joseph Pecoraro <pecoraro@apple.com> >+ >+ Web Inspector: Autoformat doesn't work on icloud.com (javascript-packed.js) >+ https://bugs.webkit.org/show_bug.cgi?id=192946 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * inspector/formatting/is-text-likely-minified-expected.txt: >+ * inspector/formatting/is-text-likely-minified.html: >+ Add a test for a long header doc at the start but minified content at the end. >+ > 2018-12-18 Joseph Pecoraro <pecoraro@apple.com> > > Web Inspector: m3u8 content not shown, it should be text >diff --git a/LayoutTests/inspector/formatting/is-text-likely-minified-expected.txt b/LayoutTests/inspector/formatting/is-text-likely-minified-expected.txt >index 09e40656ac6..10f915e283e 100644 >--- a/LayoutTests/inspector/formatting/is-text-likely-minified-expected.txt >+++ b/LayoutTests/inspector/formatting/is-text-likely-minified-expected.txt >@@ -11,3 +11,6 @@ PASS: jQuery snippet should be classified as unminified. > -- Running test case: JQuerySnippet.Minified > PASS: jQuery snippet should be classified as minified. > >+-- Running test case: JQuerySnippet.Minified >+PASS: Source with leading unminified but trailing minified source should be classified as minified. >+ >diff --git a/LayoutTests/inspector/formatting/is-text-likely-minified.html b/LayoutTests/inspector/formatting/is-text-likely-minified.html >index 42925afc1d9..3f7b5aafeec 100644 >--- a/LayoutTests/inspector/formatting/is-text-likely-minified.html >+++ b/LayoutTests/inspector/formatting/is-text-likely-minified.html >@@ -5,13 +5,13 @@ > <script> > function test() > { >- let suite = InspectorTest.createAsyncSuite("Formatting.isLikelyMinified"); >+ let suite = InspectorTest.createSyncSuite("Formatting.isLikelyMinified"); > > suite.addTestCase({ > name: "JavaScriptShortSnippet.Unminified", >- test(resolve, reject) { >+ test() { > InspectorTest.expectThat(!isTextLikelyMinified("var x = 42;\nvar y = 24;\n"), "This small JavaScript snippet should be classified as unminified."); >- resolve(); >+ return true; > } > }); > >@@ -91,9 +91,9 @@ var support = {};`; > > suite.addTestCase({ > name: "JQuerySnippet.Unminified", >- test(resolve, reject) { >+ test() { > InspectorTest.expectThat(!isTextLikelyMinified(jquerySourceFragment), "jQuery snippet should be classified as unminified."); >- resolve(); >+ return true; > } > }); > >@@ -102,12 +102,37 @@ var support = {};`; > > suite.addTestCase({ > name: "JQuerySnippet.Minified", >- test(resolve, reject) { >+ test() { > InspectorTest.expectThat(isTextLikelyMinified(jQueryMinifiedSourceFragment), "jQuery snippet should be classified as minified."); >- resolve(); >+ return true; > } > }); > >+ let sampleHeader = ` >+/*! >+ * jQuery JavaScript Library v3.1.0 >+ * https://jquery.com/ >+ * >+ * Includes Sizzle.js >+ * https://sizzlejs.com/ >+ * >+ * Copyright jQuery Foundation and other contributors >+ * Released under the MIT license >+ * https://jquery.org/license >+ * >+ * Date: 2016-07-07T21:44Z >+ */ >+ `; >+ >+ let longHeaderSource = sampleHeader.repeat(10) + jQueryMinifiedSourceFragment; >+ suite.addTestCase({ >+ name: "JQuerySnippet.Minified", >+ test() { >+ InspectorTest.expectThat(isTextLikelyMinified(longHeaderSource), "Source with leading unminified but trailing minified source should be classified as minified."); >+ return true; >+ } >+ }) >+ > suite.runTestCasesAndFinish(); > } > </script> >diff --git a/Source/WebInspectorUI/ChangeLog b/Source/WebInspectorUI/ChangeLog >index 327e3b5a611..a8e3ee63da6 100644 >--- a/Source/WebInspectorUI/ChangeLog >+++ b/Source/WebInspectorUI/ChangeLog >@@ -1,3 +1,17 @@ >+2018-12-20 Joseph Pecoraro <pecoraro@apple.com> >+ >+ Web Inspector: Autoformat doesn't work on icloud.com (javascript-packed.js) >+ https://bugs.webkit.org/show_bug.cgi?id=192946 >+ <rdar://problem/42546126> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * UserInterface/Base/Utilities.js: >+ (whitespaceRatio): >+ (isTextLikelyMinified): >+ Check the first 2500 and the last 2500 characters whitespace ratio. >+ If either is below 20% then treat as minified. >+ > 2018-12-19 Joseph Pecoraro <pecoraro@apple.com> > > ITMLKit Inspector: Computed Style Box Model section throws exceptions >diff --git a/Source/WebInspectorUI/UserInterface/Base/Utilities.js b/Source/WebInspectorUI/UserInterface/Base/Utilities.js >index 94f5a6a6202..9bf08943dc7 100644 >--- a/Source/WebInspectorUI/UserInterface/Base/Utilities.js >+++ b/Source/WebInspectorUI/UserInterface/Base/Utilities.js >@@ -1613,17 +1613,13 @@ function isFunctionStringNativeCode(str) > return str.endsWith("{\n [native code]\n}"); > } > >-function isTextLikelyMinified(content) >+function whitespaceRatio(content, start, end) > { >- const autoFormatMaxCharactersToCheck = 5000; >- const autoFormatWhitespaceRatio = 0.2; >- > let whitespaceScore = 0; >- let size = Math.min(autoFormatMaxCharactersToCheck, content.length); >+ let size = end - start; > >- for (let i = 0; i < size; i++) { >+ for (let i = start; i < end; i++) { > let char = content[i]; >- > if (char === " ") > whitespaceScore++; > else if (char === "\t") >@@ -1633,7 +1629,28 @@ function isTextLikelyMinified(content) > } > > let ratio = whitespaceScore / size; >- return ratio < autoFormatWhitespaceRatio; >+ return ratio; >+} >+ >+function isTextLikelyMinified(content) >+{ >+ const autoFormatMaxCharactersToCheck = 2500; >+ const autoFormatWhitespaceRatio = 0.2; >+ >+ if (content.length <= autoFormatMaxCharactersToCheck) { >+ let ratio = whitespaceRatio(content, 0, content.length); >+ return ratio < autoFormatWhitespaceRatio; >+ } >+ >+ let startRatio = whitespaceRatio(content, 0, autoFormatMaxCharactersToCheck); >+ if (startRatio < autoFormatWhitespaceRatio) >+ return true; >+ >+ let endRatio = whitespaceRatio(content, content.length - autoFormatMaxCharactersToCheck, content.length) >+ if (endRatio < autoFormatWhitespaceRatio) >+ return true; >+ >+ return false; > } > > function doubleQuotedString(str)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
hi
:
review+
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 192946
: 357851