Closed aidanharan closed 8 months ago
Fix for issue https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues/1131
The regex to match a view column to table column name was too vague, which could cause a similarly named view column to be matched.
The issue was found in v7.0.5.0 (containing https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1126) but the issue was actually present in previous releases (eg: v7.0.4.0). The order that the view columns were declared affected whether the issue appeared or not.
For example if you had view declaration:
CREATE VIEW bug_tests AS SELECT id AS id, dt_field as dt, dt_fieldX as dt_x FROM bug_test_tables
And performed regex of CREATE\s+VIEW.*AS\s+SELECT.*\W([\w-]*)\s+AS\s+dt on it then you would get match:
CREATE\s+VIEW.*AS\s+SELECT.*\W([\w-]*)\s+AS\s+dt
If you changed the view declaration so that dt_x is before dt:
dt_x
dt
CREATE VIEW bug_tests AS SELECT id AS id, dt_fieldX as dt_x, dt_field as dt FROM bug_test_tables
Then the same regex would match:
In the fixed I remove the CREATE VIEW ... AS SELECT ... clause to simplify the regex to match the column name followed by a non-word character.
CREATE VIEW ... AS SELECT ...
Fix for issue https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues/1131
The regex to match a view column to table column name was too vague, which could cause a similarly named view column to be matched.
The issue was found in v7.0.5.0 (containing https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1126) but the issue was actually present in previous releases (eg: v7.0.4.0). The order that the view columns were declared affected whether the issue appeared or not.
For example if you had view declaration:
And performed regex of
CREATE\s+VIEW.*AS\s+SELECT.*\W([\w-]*)\s+AS\s+dt
on it then you would get match:If you changed the view declaration so that
dt_x
is beforedt
:Then the same regex would match:
In the fixed I remove the
CREATE VIEW ... AS SELECT ...
clause to simplify the regex to match the column name followed by a non-word character.