[PR #1772] [CLOSED] WiFiManagerParameter max length and encapsulation #1826

Closed
opened 2026-02-28 02:13:08 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/tzapu/WiFiManager/pull/1772
Author: @dmadison
Created: 10/28/2024
Status: Closed

Base: masterHead: param-max-length


📝 Commits (6)

  • d17f73f Add param setValue function without length
  • baf99e4 Deprecate parameter friendship
  • f8da7b8 Refactor parameter 'length' as 'maxLength'
  • d507b97 Change param value length function name
  • 2b34425 Add negative check to param max length
  • 0111a05 Remove parameter friendship

📊 Changes

3 files changed (+39 additions, -26 deletions)

View changed files

📝 WiFiManager.cpp (+29 -17)
📝 WiFiManager.h (+9 -8)
📝 keywords.txt (+1 -1)

📄 Description

This PR performs a few fixes around the WiFiManagerParameter class to improve clarity, usability, and encapsulation:

  • The length parameter has been changed to maxLength for all class functions
    • The parameter refers to the max length of the form and the size of the internal buffer, not the length of the string passed as an argument. The internal name (_length) has not been changed to maintain compatibility with user code, as it's exposed as a protected value and through friendship with WiFiManager.
  • setValue() now has a version without a max length argument
    • The original 'length' argument was confusing as a user, since it seemed to refer to the length of the string passed in while it's actually the max length of the buffer / value in the form. This new function allows for changing the value without changing the max length.
  • getValueLength() has been changed to getValueMaxLength()
    • This better represents what is being returned, since it's the maximum length of the form / buffer and not the length of the value (i.e. what's currently in the buffer, and what's returned from the webpage). The original function is marked deprecated and has not been changed for compatibility reasons, but it would be nice if it returned the length of the value in the next major release.
  • Friendship between WiFiManagerParameter and WiFiManager has been removed
    • The few internal calls in WiFiManager have been changed to use the public functions and there is no remaining reason for the friendship to exist. Removing the friendship boosts encapsulation.
  • setValue() now checks for a negative max length
    • All of the corresponding 'length' arguments should probably be unsigned (size_t). Again, this was not changed so-as not to break backwards-compatibility.

This PR should have no breaking changes. The few items marked deprecated should be removed on the next major release.


If this is merged, here are the changes to make on the next major release:

  • WiFiManagerParameter::_length should be refactored to _maxLength
  • WiFiManagerParameter::getValueLength() const should be removed
  • All WiFiManagerParameter maxLength arguments should use size_t instead of int

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/tzapu/WiFiManager/pull/1772 **Author:** [@dmadison](https://github.com/dmadison) **Created:** 10/28/2024 **Status:** ❌ Closed **Base:** `master` ← **Head:** `param-max-length` --- ### 📝 Commits (6) - [`d17f73f`](https://github.com/tzapu/WiFiManager/commit/d17f73f5f30c19c4f4fa2748b13f626ca8635524) Add param setValue function without length - [`baf99e4`](https://github.com/tzapu/WiFiManager/commit/baf99e4915d0863771f80af270b60ecff10ced5b) Deprecate parameter friendship - [`f8da7b8`](https://github.com/tzapu/WiFiManager/commit/f8da7b8d6a3c3b76219c6d1a5fba65cb3bae7999) Refactor parameter 'length' as 'maxLength' - [`d507b97`](https://github.com/tzapu/WiFiManager/commit/d507b9771e30ff2a366ca84318624bd667311fa2) Change param value length function name - [`2b34425`](https://github.com/tzapu/WiFiManager/commit/2b34425549bab68be3fd3eb3ef70815f11cba160) Add negative check to param max length - [`0111a05`](https://github.com/tzapu/WiFiManager/commit/0111a05db63cc4386e73e9bceb44f39a6a53cbab) Remove parameter friendship ### 📊 Changes **3 files changed** (+39 additions, -26 deletions) <details> <summary>View changed files</summary> 📝 `WiFiManager.cpp` (+29 -17) 📝 `WiFiManager.h` (+9 -8) 📝 `keywords.txt` (+1 -1) </details> ### 📄 Description This PR performs a few fixes around the `WiFiManagerParameter` class to improve clarity, usability, and encapsulation: * The `length` parameter has been changed to `maxLength` for all class functions * The parameter refers to the max length of the form and the size of the internal buffer, not the length of the string passed as an argument. The internal name (`_length`) has *not* been changed to maintain compatibility with user code, as it's exposed as a protected value and through friendship with `WiFiManager`. * `setValue()` now has a version without a max length argument * The original 'length' argument was confusing as a user, since it seemed to refer to the length of the string passed in while it's actually the max length of the buffer / value in the form. This new function allows for changing the value without changing the max length. * `getValueLength()` has been changed to `getValueMaxLength()` * This better represents what is being returned, since it's the maximum length of the form / buffer and not the length of the value (i.e. what's *currently* in the buffer, and what's returned from the webpage). The original function is marked deprecated and has not been changed for compatibility reasons, but it would be nice if it returned the length of the value in the next major release. * Friendship between `WiFiManagerParameter` and `WiFiManager` has been removed * The few internal calls in `WiFiManager` have been changed to use the public functions and there is no remaining reason for the friendship to exist. Removing the friendship boosts encapsulation. * `setValue()` now checks for a negative max length * All of the corresponding 'length' arguments should probably be unsigned (`size_t`). Again, this was not changed so-as not to break backwards-compatibility. This PR should have **no** breaking changes. The few items marked deprecated should be removed on the next major release. --- If this is merged, here are the changes to make on the next major release: * `WiFiManagerParameter::_length` should be refactored to `_maxLength` * `WiFiManagerParameter::getValueLength() const` should be removed * All `WiFiManagerParameter` `maxLength` arguments should use `size_t` instead of `int` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-28 02:13:08 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#1826
No description provided.