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

Use regex lazy quantifier to match first occurrence in combined validation rules #4049

Merged
merged 2 commits into from
Jan 9, 2024

Conversation

kenfai
Copy link
Contributor

@kenfai kenfai commented Dec 14, 2023

Fix rules formatting to use regex lazy quantifier(?) so that only the first occurrence in combined validation rules is being matched for the prepend of array wildcard(*) validation character to the column name.

1️⃣ Why should it be added? What are the benefits of this change?
To fix the Database connection [3] not configured. error when using combined validation rules that contain more than 1 colon(:).

For example:

'required_with:mobile_no|nullable|unique:users,user_name|numeric'

After RowValidator::formatRule() call, the result becomes:

'required_with:mobile_no|nullable|unique:*.users,user_name|numeric'

In Laravel validation, unique:*.users means specifying a custom database connection:
https://laravel.com/docs/8.x/validation#rule-unique which is not the expected behaviour. Since no database connection is defined, the following error will be returned by Laravel validation:

Database connection [3] not configured.

This fix will output the expected format:

'required_with:*.mobile_no|nullable|unique:users,user_name|numeric'

The wildcard(*) character is added to the right place.

Reported issues:

2️⃣ Does it contain multiple, unrelated changes? Please separate the PRs out.
No.

3️⃣ Does it include tests, if possible?
Not required.

4️⃣ Any drawbacks? Possible breaking changes?
No.

5️⃣ Mark the following tasks as done:

  • Checked the codebase to ensure that your feature doesn't already exist.
  • Take note of the contributing guidelines.
  • Checked the pull requests to ensure that another person hasn't already submitted a fix.
  • Added tests to ensure against regression.

6️⃣ Thanks for contributing! 🙌
Welcome.

@patrickbrouwers
Copy link
Member

Can you please add a test for this

@kenfai
Copy link
Contributor Author

kenfai commented Dec 16, 2023

Can you please add a test for this

Added a test for the fix.

@kenfai
Copy link
Contributor Author

kenfai commented Jan 8, 2024

@patrickbrouwers all good to merge?

@patrickbrouwers patrickbrouwers merged commit 5ab638f into SpartnerNL:3.1 Jan 9, 2024
16 checks passed
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.

None yet

2 participants