Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[5.4] Can't Wrap DB Names Containing Spaces When Aliasing (#17312)
* Can't Wrap DB Names Containing Spaces When Aliasing Database names containing spaces are perfectly legal in Microsoft SQL Server. Currently, when using SQL Server, if you have a database which includes spaces, the grammar handles wrapping it fine. So this: My Sample Database.dbo.my_table.my_column Correctly becomes: [My Sample Database].[dbo].[my_table].[my_column] *But* if you also try to alias a column when the database contains spaces, it breaks. This: My Sample Database.dbo.my_table.my_column AS my_aliased_column Becomes: [My] AS [Sample] I have traced the error to Database/Grammar/wrapAliasedValue() using explode( ' ' ) - the code thinks the spaces in the database name are the spaces around the "AS". We can fix this by using regex instead of explode, splitting on the "AS" more accurately. Just replace the explode with this: $segments = preg_split( '/\s+as\s+/i', $value ); Note: When you have an Eloquent belongsToMany method that has to include the database name (eg. we need to join across DBs), this type of alias is created automatically, generating this error. I originally committed this to 5.3 (laravel/framework#17292) and was asked to commit here instead. * Adding Tests RE: laravel/framework#17312
- Loading branch information