Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 21, 2025

Fix HTML Reporter: Handle nested arrays in system info

Problem

The HTML reporter crashes when getMachineInfo() returns data with nested arrays. Example:

edgeInfo: [ 'Edge', [ 'Chromium (140.0.3485.54)' ], 'N/A' ]

Error: text.replace is not a function occurs in escapeHtml() when it tries to call .replace() on an array.

Solution

  • Investigated issue and identified root causes in escapeHtml() and generateSystemInfoHtml()
  • Fixed escapeHtml() to handle non-string inputs:
    • Converts arrays to strings by recursively flattening nested arrays and joining with commas
    • Handles objects and other types by converting to strings
    • Maintains HTML escaping for all inputs
  • Updated generateSystemInfoHtml() with clearer documentation
  • Created comprehensive unit tests covering:
    • Nested arrays (the original issue case)
    • Deeply nested arrays (recursive flattening)
    • HTML escaping within arrays
    • Edge cases (null, undefined, empty strings, numbers, objects)
    • Mixed array types
  • Refactored tests to follow DRY principle (removed duplicate helper functions)
  • Verified fix with manual integration tests
  • All 15 unit tests pass successfully

Code Review Feedback Addressed

  • ✅ Removed duplicate escapeHtml helper functions from test file
  • ✅ Implemented recursive flattening for deeply nested arrays
  • ✅ Added comprehensive documentation

Testing

All tests pass:

✓ Nested arrays like ['Edge', ['Chromium (140.0.3485.54)'], 'N/A']
✓ Deeply nested arrays like ['Level1', ['Level2', ['Level3']], 'End']
✓ HTML escaping in arrays
✓ Edge cases (null, undefined, etc.)

The fix is minimal and surgical - only modifying the escapeHtml() function to properly handle non-string inputs with recursive array flattening before attempting HTML escape operations.

Original prompt

This section details on the original issue you should resolve

<issue_title>html reporter doesn't work</issue_title>
<issue_description>Sometimes the information returned by await getMachineInfo() looks like the example below.

{
nodeInfo: [
'Node',
'22.14.0',
'~\AppData\Local\fnm_multishells\19200_1763624547202\node.EXE'
],
osInfo: [ 'OS', 'Windows 10 10.0.19045' ],
cpuInfo: [ 'CPU', '(12) x64 12th Gen Intel(R) Core(TM) i5-12500' ],
chromeInfo: [ 'Chrome', '142.0.7444.163', 'N/A' ],
edgeInfo: [ 'Edge', [ 'Chromium (140.0.3485.54)' ], 'N/A' ],
firefoxInfo: undefined,
safariInfo: [ 'Safari', 'N/A' ],
playwrightBrowsers: 'chromium: 136.0.7103.25, firefox: 137.0, webkit: 18.4'
}

And the escapeHtml method will cause an immediate exit when handling data like edgeinfo.

  function escapeHtml(text) {
    output.print(text)
    if (!text) return ''
    const string =  text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;')
    output.print(string)
    return string
  }
```</issue_description>

<agent_instructions>- investigate the issue and provide better approach 
- fix the issue
- add tests</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits November 21, 2025 06:33
- Updated escapeHtml() to handle non-string inputs including arrays and nested arrays
- Arrays are flattened and joined with commas before HTML escaping
- Added documentation to generateSystemInfoHtml() for clarity
- Added comprehensive unit tests for escapeHtml functionality
- Verified fix handles the exact issue case: edgeInfo with nested array

Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com>
- Refactored escapeHtml to use recursive flattening for deeply nested arrays
- Removed duplicate helper functions from test file (DRY principle)
- All 15 unit tests pass successfully
- Verified deep nesting support (e.g., [['Level2', ['Level3']]])

Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com>
- Added maxDepth parameter (default: 100) to prevent stack overflow
- Returns string representation if depth limit reached
- Maintains full functionality for normal use cases
Copilot AI requested a review from kobenguyent November 21, 2025 06:49
@kobenguyent kobenguyent marked this pull request as ready for review November 21, 2025 07:20
@kobenguyent kobenguyent merged commit 5f1269b into 3.x Nov 21, 2025
13 of 14 checks passed
@kobenguyent kobenguyent deleted the copilot/fix-html-reporter-issue branch November 21, 2025 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

html reporter doesn't work

2 participants