Skip to content

fix: prevent crash when comparing Symbol to other types#259

Open
Mubashir78 wants to merge 1 commit into
lukeed:masterfrom
Mubashir78:fix/symbol-comparison-crash
Open

fix: prevent crash when comparing Symbol to other types#259
Mubashir78 wants to merge 1 commit into
lukeed:masterfrom
Mubashir78:fix/symbol-comparison-crash

Conversation

@Mubashir78

Copy link
Copy Markdown

The direct() function in the diff module calls String() on its inputs to compute their display lengths. String(Symbol()) throws a TypeError, causing an uncaught exception when comparing Symbol values to other types via assert.is() or assert.equal().

Extract a stringifyValue() helper that handles Symbol gracefully by using its description string, and avoid mutating the original input/expect parameters for the string representation.

Fixes #251

Test plan

  • Existing diff tests continue to pass
  • direct(Symbol("foo"), 42) now returns a proper diff string instead of throwing

The direct() function in the diff module calls String() on its inputs
to compute their display lengths. String(Symbol()) throws a TypeError,
causing an uncaught exception when comparing Symbol values to other
types via assert.is() or assert.equal().

Extract a stringifyValue() helper that handles Symbol gracefully by
using its description, and avoid mutating the original input/expect
parameters to prevent similar issues.
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.

BUG: Comparison between Symbol and number causes uncaught exception

1 participant