Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Validator] Add additional versions (*_NO_PUBLIC, *_ONLY_PRIV & *_ONLY_RES) in IP address constraint #51777

Closed
wants to merge 32 commits into from
Closed

Conversation

Ninos
Copy link
Contributor

@Ninos Ninos commented Sep 28, 2023

Q A
Branch? 6.4
Bug fix? no
New feature? yes
Deprecations? no
License MIT

Possibility to allow only private or only reserved ips.

  • Enhancement: Add *_NO_PUBLIC, *_ONLY_PRIV & *_ONLY_RES as possible versions in Ip constraint
  • Enhancement: Possibility to use all Ip versions in Cidr constraint

PS: In Ip constraint I changed the default version from V4 to ALL, think it's time to support also V6 by default :-) Otherwise we can revert that, but normally should not break much...

…constraint

Added: MAC address constraint
Changed: Default version filter from IPv4 to ALL (IPv4 & IPv6)
@carsonbot carsonbot changed the title Mac address & IP address constraint [Validator] Mac address & IP address constraint Sep 29, 2023
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Here are some comments. Changing the defaults look undesired to me since it would change the behavior of existing apps without notice.
Can you also please update the title of your PR so that it can be useful for readers in the auto-generated changelog when doing the release?

UPGRADE-6.4.md Outdated Show resolved Hide resolved
src/Symfony/Component/Validator/CHANGELOG.md Outdated Show resolved Hide resolved
src/Symfony/Component/Validator/Constraints/Ip.php Outdated Show resolved Hide resolved
src/Symfony/Component/Validator/Constraints/Ip.php Outdated Show resolved Hide resolved
src/Symfony/Component/Validator/Constraints/Mac.php Outdated Show resolved Hide resolved
src/Symfony/Component/Validator/Constraints/Mac.php Outdated Show resolved Hide resolved
src/Symfony/Component/Validator/Constraints/Mac.php Outdated Show resolved Hide resolved
src/Symfony/Component/Validator/Constraints/Mac.php Outdated Show resolved Hide resolved
src/Symfony/Component/Validator/Constraints/Mac.php Outdated Show resolved Hide resolved
@xabbuh
Copy link
Member

xabbuh commented Oct 2, 2023

I am not convinced that a MAC address validator is a common enough use case to be included in the Symfony core.

Ninos and others added 8 commits October 5, 2023 08:11
Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
@Ninos Ninos changed the title [Validator] Mac address & IP address constraint [Validator] Added mac address constraint & additional versions *_ONLY_PRIV & *_ONLY_RES in IP address constraint Oct 5, 2023
@Ninos
Copy link
Contributor Author

Ninos commented Oct 5, 2023

Thanks for the PR. Here are some comments. Changing the defaults look undesired to me since it would change the behavior of existing apps without notice. Can you also please update the title of your PR so that it can be useful for readers in the auto-generated changelog when doing the release?

Thx for review, merged your commits, reverted your comments & changed title :-)

@stof
Copy link
Member

stof commented Oct 5, 2023

If we want to change the default version, we would have to make it configurable in the validator:

  • make the version field of the constraint nullable and default to null
  • configure a default version in the validator (defaulting to V4 for BC reasons), that is used when the constraint version is null
  • add a configuration setting in FrameworkBundle to configure the default IP version.

But to me, this deserves a separate PR than this one adding new version constants. It deserves to have a separate discussion instead of being bundled in the same decision to merge or no (note that I would have separated the Mac constraint as well, to allow separating the decisions as well).

@fabpot fabpot modified the milestones: 6.4, 7.1 Oct 18, 2023
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

LGTM with one comment about naming


self::V4_ONLY_RES,
self::V6_ONLY_RES,
self::ALL_ONLY_RES,
Copy link
Member

Choose a reason for hiding this comment

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

RES is super cryptic, let's go with the full RESERVED word

Let's duplicate all consts to add these full-word names as aliases (PRIV also)

@Ninos
Copy link
Contributor Author

Ninos commented Nov 4, 2023

Seems my responses are still on pending... I'll reply as seperate comment:

I used the same suffix, which was used as filter flag (e.g. FILTER_FLAG_NO_PRIV_RANGE, see also: https://www.php.net/manual/de/filter.filters.flags.php).

Also this constraint already contains constants with _PRIV & _RES suffix, see already existing constant *_ONLY_PRIV:
https://github.com/symfony/symfony/blob/6.4/src/Symfony/Component/Validator/Constraints/Ip.php#L35

We cannot just rename new constants to PRIVATE or RESERVED, this will be inconsistent. We could also rename old constrants to new suffix, but then we need to add additional complexity for backward-compatibility...

@Seb33300
Copy link
Contributor

Seb33300 commented Nov 4, 2023

We cannot just rename new constants to PRIVATE or RESERVED, this will be inconsistent. We could also rename old constants to new suffix, but then we need to add additional complexity for backward-compatibility...

@nicolas-grekas suggested to duplicate all names in his latest comment.

@Ninos
Copy link
Contributor Author

Ninos commented Nov 5, 2023

@Seb33300 @nicolas-grekas @OskarStark renamed & deprecated old constants. Hope it's fine now :-)

@Ninos
Copy link
Contributor Author

Ninos commented Nov 6, 2023

I've also updated Cidr constraint to use possible versions defined in Ip constraint. Please check also :-)

@Ninos Ninos changed the title [Validator] Add additional versions (*_ONLY_PRIV & *_ONLY_RES) in IP address constraint [Validator] Add additional versions (*_NO_PUBLIC, *_ONLY_PRIV & *_ONLY_RES) in IP address constraint Nov 6, 2023
@nicolas-grekas
Copy link
Member

(please rebase, don't merge - you can also squash as we won't keep the history)

@Ninos
Copy link
Contributor Author

Ninos commented Nov 20, 2023

(please rebase, don't merge - you can also squash as we won't keep the history)

Ok now I have a problem.. :D Give me some min, may I'll create a new branch if possible to retag this MR :/

@Ninos
Copy link
Contributor Author

Ninos commented Nov 20, 2023

@nicolas-grekas I've created a new branch based on 7.1, hope this is fine :( Sry for spamming, I'll try to rebase my mac addresses branch instead :)

See also: #52658

@Ninos Ninos closed this Nov 20, 2023
@Ninos Ninos deleted the constraints-networking branch November 21, 2023 19:51
nicolas-grekas added a commit that referenced this pull request Jan 2, 2024
… MAC address (Ninos)

This PR was merged into the 7.1 branch.

Discussion
----------

[Validator] Add `MacAddress` constraint for validating MAC address

| Q             | A
| ------------- | ---
| Branch?       | 7.1
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| License       | MIT

Possibility to validate against mac address.

See also past discussion: #51777

Commits
-------

06ccf62 [Validator] Add `MacAddress` constraint for validating MAC address
fabpot added a commit that referenced this pull request Feb 3, 2024
…_ONLY_PRIV` & `*_ONLY_RES`) in IP address & CIDR constraint (Ninos)

This PR was squashed before being merged into the 7.1 branch.

Discussion
----------

[Validator] Add additional versions  (`*_NO_PUBLIC`, `*_ONLY_PRIV` & `*_ONLY_RES`) in IP address & CIDR constraint

| Q             | A
| ------------- | ---
| Branch?       | 7.1
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| License       | MIT

Possibility to allow no public, only private or only reserved ips.

- Enhancement: Add `*_NO_PUBLIC`, `*_ONLY_PRIV` & `*_ONLY_RES` as possible versions in `Ip` constraint
- Enhancement: Possibility to use all `Ip` versions in `Cidr` constraint

See also old MR: #51777

Commits
-------

291ef1c [Validator] Add additional versions  (`*_NO_PUBLIC`, `*_ONLY_PRIV` & `*_ONLY_RES`) in IP address & CIDR constraint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants