Skip to content

Conversation

@Abdel-Monaam-Aouini
Copy link
Contributor

@Abdel-Monaam-Aouini Abdel-Monaam-Aouini commented Oct 27, 2024

Refactor acceptsCharsets to support flexible charset input formats

This change improves the acceptsCharsets method to handle multiple input formats:

  • Single charset string (e.g., "utf-8")
  • Multiple charset arguments (e.g., "utf-8", "iso-8859-1")
  • Comma-delimited charset lists (e.g., "utf-8, iso-8859-1")

Updates include:

  • Enhanced documentation with clear examples and parameter descriptions
  • Modernized code using const instead of var
  • Improved function signature to use rest parameters (...charsets)
  • Clarified behavior regarding Accept-Charset header matching
  • Updated return value documentation to specify array return possibility

The changes make the API more flexible while maintaining backwards compatibility.

@UlisesGascon
Copy link
Member

Hey @Abdel-Monaam-Aouini! Thanks for this PR... can you explain the motivation for this change?

@Abdel-Monaam-Aouini
Copy link
Contributor Author

Hey @Abdel-Monaam-Aouini! Thanks for this PR... can you explain the motivation for this change?

The motivation for this change is to improve developer experience and make the acceptsCharsets API more flexible and intuitive. Currently, the method's behavior and supported input formats aren't clearly documented, which can lead to confusion.

Key motivations:

  1. Support Multiple Input Formats:

    • Developers should be able to check charset acceptance using the most convenient format for their use case
    • Some might prefer passing multiple arguments: req.acceptsCharsets('utf-8', 'iso-8859-1')
    • Others might work with comma-delimited strings: req.acceptsCharsets('utf-8, iso-8859-1')
    • The current documentation doesn't make these options clear
  2. Modern JavaScript Practices:

    • Updated the implementation to use modern ES6+ features like const and rest parameters
    • This makes the code more maintainable and consistent with modern JavaScript standards
  3. Better Documentation:

    • Added clear examples showing different usage patterns
    • Improved parameter and return value documentation
    • Made it explicit how the method interacts with the Accept-Charset header

The changes don't break existing functionality but make the API more developer-friendly and better documented. This helps reduce potential confusion and makes the feature more accessible to new Express.js users.

@IamLizu IamLizu added the future label Dec 8, 2024
Copy link
Member

@wesleytodd wesleytodd left a comment

Choose a reason for hiding this comment

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

Looking good. I think both the docs and the modernization in this are worth doing in this case.

@jonchurch jonchurch added semver-patch This change is a semver patch and removed future labels Jan 5, 2026
@bjohansebas bjohansebas added the 5.x label Jan 6, 2026
@bjohansebas
Copy link
Member

The failing test is due to #6969

@bjohansebas bjohansebas merged commit 6cd404e into expressjs:master Jan 7, 2026
31 of 51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5.x semver-patch This change is a semver patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants