Skip to content

fix: use correct parameter name in _preferredTypeLegacy function#170

Open
Ayoub-Mabrouk wants to merge 2 commits intojshttp:masterfrom
Ayoub-Mabrouk:fix/preferred-type-legacy-variable-name
Open

fix: use correct parameter name in _preferredTypeLegacy function#170
Ayoub-Mabrouk wants to merge 2 commits intojshttp:masterfrom
Ayoub-Mabrouk:fix/preferred-type-legacy-variable-name

Conversation

@Ayoub-Mabrouk
Copy link
Contributor

The function was using undefined variable 'extension' instead of the parameter 'ext', causing incorrect behavior when comparing legacy MIME type resolution logic. This bug was introduced in commit 541f9c5 when the function was extracted from populateMaps during the mime-score refactoring.

  • Changed exports.types[extension] to exports.types[ext]
  • Fixes incorrect variable reference that would cause undefined behavior

The function was using undefined variable 'extension' instead of the parameter 'ext', causing incorrect behavior when comparing legacy MIME type resolution logic. This bug was introduced in commit 541f9c5 when the function was extracted from populateMaps during the mime-score refactoring.

- Changed exports.types[extension] to exports.types[ext]
- Fixes incorrect variable reference that would cause undefined behavior
Copy link
Member

@UlisesGascon UlisesGascon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Ayoub-Mabrouk! Great catch... can we include a test to prevent regressions?

@Ayoub-Mabrouk
Copy link
Contributor Author

Hey @Ayoub-Mabrouk! Great catch... can we include a test to prevent regressions?

thanks @UlisesGascon
The bug in _preferredTypeLegacy (using extension instead of ext) is hard to test indirectly because:

  • Module initialization timing: _preferredTypeLegacy is called during populateMaps, which runs at module load. Tests run after initialization, so we can't easily control the execution context.
  • State-dependent behavior: The function checks exports.types[ext], which changes during the loop. The bug accesses exports.types[undefined], which doesn't throw but causes incorrect logic that's hard to detect indirectly.
  • Indirect testing is unreliable: Testing through populateMaps by re-requiring the module and checking results is fragile and may not catch the bug.

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.

2 participants