Changeset 291712 in webkit
- Timestamp:
- Mar 22, 2022, 3:22:09 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/inspector/unit-tests/string-utilities-expected.txt (modified) (1 diff)
-
LayoutTests/inspector/unit-tests/string-utilities.html (modified) (1 diff)
-
Source/WebInspectorUI/ChangeLog (modified) (1 diff)
-
Source/WebInspectorUI/UserInterface/Base/Utilities.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r291710 r291712 1 2022-03-22 Patrick Angle <pangle@apple.com> 2 3 Web Inspector: console.log print strings contains '%_' result is Object 4 https://bugs.webkit.org/show_bug.cgi?id=235061 5 6 Reviewed by Devin Rousso. 7 8 * inspector/unit-tests/string-utilities-expected.txt: 9 * inspector/unit-tests/string-utilities.html: 10 1 11 2022-03-22 Matteo Flores <matteo_flores@apple.com> 2 12 -
trunk/LayoutTests/inspector/unit-tests/string-utilities-expected.txt
r286611 r291712 20 20 PASS: integer format specifier with Infinity argument should show "NaN" 21 21 PASS: integer format specifier with NaN argument should show "NaN" 22 Testing string with unknown specifier. 23 WARN: String.format("%_ %s", "first", "second"): Unsupported format specifier "%_" will be ignored. 24 PASS: Formatter string with unknown specifier should not replace unknown specifier. 25 PASS: Formatter string with unknown specifier should have an unused substitution value. 22 26 23 27 -- Running test case: String.prototype.extendedLocaleCompare -
trunk/LayoutTests/inspector/unit-tests/string-utilities.html
r286611 r291712 31 31 InspectorTest.expectThat("%d".format(Infinity) === "NaN", "integer format specifier with Infinity argument should show \"NaN\""); 32 32 InspectorTest.expectThat("%d".format(NaN) === "NaN", "integer format specifier with NaN argument should show \"NaN\""); 33 34 InspectorTest.log("Testing string with unknown specifier."); 35 let formatWithUnknownSpecifiers = String.format("%_ %s", ["first", "second"], String.standardFormatters, "", function(a, b) { return a + b; }); 36 InspectorTest.expectThat(formatWithUnknownSpecifiers.formattedResult === "%_ first", "Formatter string with unknown specifier should not replace unknown specifier."); 37 InspectorTest.expectThat(formatWithUnknownSpecifiers.unusedSubstitutions[0] === "second", "Formatter string with unknown specifier should have an unused substitution value."); 38 33 39 return true; 34 40 } -
trunk/Source/WebInspectorUI/ChangeLog
r291628 r291712 1 2022-03-22 Patrick Angle <pangle@apple.com> 2 3 Web Inspector: `console.log` format strings containing invalid specifiers results in `[Object object]` replacing the specifier instead of ignoring the invalid specifier 4 https://bugs.webkit.org/show_bug.cgi?id=235061 5 6 Reviewed by Devin Rousso. 7 8 Logged console messages previously allows an specifier, even invalid ones, to be replaced with values. We should 9 instead ignore the invalid specifier to match Firefox's behavior. (Chrome's behavior currently is to remove the 10 invalid specifier from the result without replacing it with the first next available substitution value.) 11 12 Other call sites using `String.format` are handling localized strings or other backend-provided strings that 13 should always be well-formatted, so falling back to handling a format specifier as a string is not a particularly 14 useful behavior. 15 16 * UserInterface/Base/Utilities.js: 17 (value): 18 1 19 2022-03-22 Nikita Vasilyev <nvasilyev@apple.com> 2 20 -
trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js
r287590 r291712 1126 1126 var tokens = String.tokenizeFormatString(format); 1127 1127 var usedSubstitutionIndexes = {}; 1128 let ignoredUnknownSpecifierCount = 0; 1128 1129 1129 1130 for (var i = 0; i < tokens.length; ++i) { … … 1140 1141 } 1141 1142 1142 if (token.substitutionIndex >= substitutions.length) { 1143 let substitutionIndex = token.substitutionIndex - ignoredUnknownSpecifierCount; 1144 if (substitutionIndex >= substitutions.length) { 1143 1145 // If there are not enough substitutions for the current substitutionIndex 1144 1146 // just output the format specifier literally and move on. 1145 error("not enough substitution arguments. Had " + substitutions.length + " but needed " + ( token.substitutionIndex + 1) + ", so substitution was skipped.");1147 error("not enough substitution arguments. Had " + substitutions.length + " but needed " + (substitutionIndex + 1) + ", so substitution was skipped."); 1146 1148 result = append(result, "%" + (token.precision > -1 ? token.precision : "") + token.specifier); 1147 1149 continue; 1148 1150 } 1149 1151 1150 usedSubstitutionIndexes[token.substitutionIndex] = true;1151 1152 1152 if (!(token.specifier in formatters)) { 1153 // Encountered an unsupported format character, treat as a string.1154 warn("unsupported format character \u201C" + token.specifier + "\u201D. Treating as a string.");1155 result = append(result, substitutions[token.substitutionIndex]);1153 warn(`Unsupported format specifier "%${token.specifier}" will be ignored.`); 1154 result = append(result, "%" + token.specifier); 1155 ++ignoredUnknownSpecifierCount; 1156 1156 continue; 1157 1157 } 1158 1158 1159 result = append(result, formatters[token.specifier](substitutions[token.substitutionIndex], token)); 1159 usedSubstitutionIndexes[substitutionIndex] = true; 1160 result = append(result, formatters[token.specifier](substitutions[substitutionIndex], token)); 1160 1161 } 1161 1162
Note:
See TracChangeset
for help on using the changeset viewer.