Skip to content

[Validator] Add Xml constraint #57365

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

Open
wants to merge 1 commit into
base: 7.3
Choose a base branch
from

Conversation

sfmok
Copy link
Contributor

@sfmok sfmok commented Jun 10, 2024

Q A
Branch? 7.3
Bug fix? no
New feature? yes
Deprecations? no
Issues No
License MIT

Add Xml constraint

@carsonbot carsonbot added this to the 7.2 milestone Jun 10, 2024
@carsonbot carsonbot changed the title Add YAML, XML and JWT format constraints [Validator] Add YAML, XML and JWT format constraints Jun 12, 2024
@OskarStark
Copy link
Contributor

Did you check

?

@OskarStark
Copy link
Contributor

OskarStark commented Jun 15, 2024

Yaml constraint was merged, so please rebase

@OskarStark OskarStark changed the title [Validator] Add YAML, XML and JWT format constraints [Validator] Add XML and JWT format constraints Jun 15, 2024
@sfmok sfmok force-pushed the feat/new-constraints branch from 9708e02 to 1edfe83 Compare June 17, 2024 13:47
@sfmok sfmok changed the title [Validator] Add XML and JWT format constraints [Validator] Add XML constraint Jun 17, 2024
@sfmok
Copy link
Contributor Author

sfmok commented Jun 17, 2024

I've made the following changes:

  • Removed format abstraction
  • Removed the Yaml constraint from this PR since it has already been merged
  • Reverted the Json constraint changes to prevent breaking the translation
  • Remove the Jwt constraint for now, as verifying the signature requires extensive work. I will likely push a separate PR for it later.
  • Adjusted the Xml constraint to support only the modern method of defining constraints

@OskarStark OskarStark changed the title [Validator] Add XML constraint [Validator] Add Xml constraint Jun 17, 2024
Copy link
Contributor

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

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

Needs a rebase

Copy link
Member

@alexandre-daubois alexandre-daubois left a comment

Choose a reason for hiding this comment

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

Just a few nitpicks 🙂 Nice PR!

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.

Asserting that a file is XML is pretty weak as a check: one always expects some structure in the XML. It'd be natural to me to allow passing an XSD, isn't it? Up to improve the PR in this direction?

@sfmok sfmok force-pushed the feat/new-constraints branch 2 times, most recently from b7ae934 to 08515a5 Compare June 25, 2024 14:02
@sfmok
Copy link
Contributor Author

sfmok commented Jun 27, 2024

Asserting that a file is XML is pretty weak as a check: one always expectes some structure in the XML. It'd be natural to me to allow passing an XSD, isn't it? Up to improve the PR in this direction?

@nicolas-grekas Thank you for your feedback. The constraint is intended to assert a string value rather than a file.
I'm not sure about allowing XSD checks, but I will consider supporting it if we receive more positive feedback either before or after merging the PR

Copy link
Contributor

@94noni 94noni left a comment

Choose a reason for hiding this comment

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

Nice

@sfmok
Copy link
Contributor Author

sfmok commented Nov 5, 2024

Any updates?

@fabpot fabpot modified the milestones: 7.2, 7.3 Nov 20, 2024
@fabpot
Copy link
Member

fabpot commented Feb 26, 2025

Asserting that a file is XML is pretty weak as a check: one always expectes some structure in the XML. It'd be natural to me to allow passing an XSD, isn't it? Up to improve the PR in this direction?

@nicolas-grekas Thank you for your feedback. The constraint is intended to assert a string value rather than a file. I'm not sure about allowing XSD checks, but I will consider supporting it if we receive more positive feedback either before or after merging the PR

I also think that supporting validating the XML content against a schema would make this feature more useful.

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.

Status: needs work

Still up to continue the PR?

@sfmok
Copy link
Contributor Author

sfmok commented Mar 28, 2025

@nicolas-grekas Yes, I'll work on it when I have some free time.

@sfmok sfmok force-pushed the feat/new-constraints branch from 92712d9 to 0a18fe2 Compare April 17, 2025 19:45
@sfmok
Copy link
Contributor Author

sfmok commented Apr 18, 2025

@nicolas-grekas & @fabpot: Thanks again for the feedback. XSD schema validation is now supported.

) {
parent::__construct(null, $groups, $payload);

if (null !== $this->schemaPath && !file_exists($this->schemaPath)) {
Copy link
Member

@alexandre-daubois alexandre-daubois Apr 18, 2025

Choose a reason for hiding this comment

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

Let's use is_readable() to ensure that the file exists and can actually be read:

Suggested change
if (null !== $this->schemaPath && !file_exists($this->schemaPath)) {
if (null !== $this->schemaPath && !is_readable($this->schemaPath)) {

Copy link
Member

Choose a reason for hiding this comment

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

In this case, you also need to change the error message: "file does not exist or cannot be read".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your valuable feedback. Resolved

@sfmok sfmok force-pushed the feat/new-constraints branch from 0a18fe2 to 5241b22 Compare April 18, 2025 17:30
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.

9 participants