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

Fix #133: Allow some special chars in table name #134

Merged
merged 6 commits into from
Sep 23, 2024

Conversation

ahmadasjad
Copy link
Contributor

@ahmadasjad ahmadasjad commented Sep 19, 2024

Fixes #133

Table name regex correction
Exception handling for syntax error when passing a wrong table name

Regex test: https://regex101.com/r/QmSWaW/1

Q A
Is bugfix? ✔️
New feature?
Breaks BC?

dot(in postgreSql)
-(in PostgreSQL/SQLite/SQL Server) with double qoute or with backticks in MySql
Copy link

codecov bot commented Sep 19, 2024

Codecov Report

Attention: Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 39.59%. Comparing base (9ba020a) to head (411aba0).
Report is 14 commits behind head on master.

Files with missing lines Patch % Lines
src/Validator/TableExistsHandler.php 25.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #134      +/-   ##
============================================
- Coverage     39.63%   39.59%   -0.04%     
- Complexity      226      227       +1     
============================================
  Files            33       34       +1     
  Lines           873      841      -32     
============================================
- Hits            346      333      -13     
+ Misses          527      508      -19     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ahmadasjad ahmadasjad changed the title Fix #133: Table name regex correction Fix #133: Allow some special chars in table name Sep 19, 2024
src/Generator/ActiveRecord/Command.php Outdated Show resolved Hide resolved
@@ -24,7 +24,7 @@ public function __construct(
private readonly string $namespace = 'App\\Model',
#[Required]
#[Regex(
pattern: '/^[a-z_][a-z0-9_]*$/i',
pattern: '/^[\w-]+(?:\.[\w-]+)?$/i',
Copy link
Member

Choose a reason for hiding this comment

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

Can you add tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't add it as the test environment isn't set up yet in the repo.
An outside test can be seen here: https://regex101.com/r/aLjS42/1

Copy link
Member

Choose a reason for hiding this comment

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

Actually there are some bugs: https://regex101.com/r/KX8vqz/1

Copy link
Member

Choose a reason for hiding this comment

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

Maybe kind of this https://regex101.com/r/B8gCXv/1

Copy link
Member

Choose a reason for hiding this comment

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

Also may be several dots. For example, in MSSQL: database_name.schema_name.table_name.

The table name specification is needed.

Copy link
Member

Choose a reason for hiding this comment

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

I suggest to check only symbols, for example, /^[\w-"]+$/`.
And do a more detailed check later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suggest to check only symbols, for example, /^[\w-"]+$/`. And do a more detailed check later.

I'm also of the same opinion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know which one I should use.

^(["'`]?)([\w][\w-]*)\1(?:\.((?1))(?2)\3)*$

https://regex101.com/r/3zbKmI/1

OR

^[\w\-."`]+$

https://regex101.com/r/3b3NYH/1

Copy link
Member

Choose a reason for hiding this comment

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

afaik - is not permitted to use, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

src/Validator/TableExistsHandler.php Outdated Show resolved Hide resolved
Copy link
Member

@samdark samdark left a comment

Choose a reason for hiding this comment

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

Code itself looks good 👍

@samdark samdark merged commit cce28a9 into yiisoft:master Sep 23, 2024
5 of 10 checks passed
@samdark
Copy link
Member

samdark commented Sep 23, 2024

Thank you!

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.

Allow to use dot in middle of table name in AR command
4 participants