[react-devtools] Fix trailing percent sign in formatConsoleArguments …
Summary
formatConsoleArguments (used by the DevTools backend to inline console substitutions) walks the format string and inlines %s/%d/%i/%f arguments while leaving %c/%o/%O in place. For each % it reads the next character to decide what to do.
When the format string ends with a lone % - e.g. console.log('Progress 100%', value) - the character after % is undefined, and the default branch ran:
template += `%${nextChar}`; // -> "%undefined"
So the function emitted the literal text %undefined:
formatConsoleArguments('Progress 100%', 'extra');
// before: ['Progress 100%undefined', 'extra']
// after: ['Progress 100%', 'extra']
Browsers render a trailing % in a console format string as a literal percent sign, so this PR keeps it as % when there is no following character.
How did you test this change?
Added a keeps a trailing percent sign test to the existing formatConsoleArguments suite in utils-test.js (covering both a bare trailing % and one that follows another substitution). Since the function is pure and import-free, I also verified the patched logic against every existing case in that suite plus the new ones to confirm there are no regressions.
Commit 53b5c3c authored
1 parent 247fbb4 commit 53b5c3c
2 files changed
Lines changed: 15 additions & 1 deletion
File tree
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | | 501 | 501 |
| | | 502 | 502 |
| | | 503 | 503 |
| | | | 504 | + |
| | | | 505 | + |
| | | | 506 | + |
| | | | 507 | + |
| | | | 508 | + |
| | | | 509 | + |
| | | | 510 | + |
| | | 504 | 512 |
| | | 505 | 513 |
Lines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | | 64 | 64 |
| | | 65 | 65 |
| | | 66 | 66 |
| | | 67 | | - |
| | | | 67 | + |
| | | | 68 | + |
| | | | 69 | + |
| | | | 70 | + |
| | | | 71 | + |
| | | | 72 | + |
| | | | 73 | + |
| | | 68 | 74 |
| | | 69 | 75 |
| | | 70 | 76 |
0 commit comments
Comments
No comments yet. Start the discussion.