Merge pull request #10462 from creative-commoners/pulls/5/rescue-master-join-aliases

Rescue Master Branch PR: Fix SQLConditionalExpression::getJoins so it always adds explicit aliases
This commit is contained in:
Steve Boyd 2022-08-24 15:33:41 +12:00 committed by GitHub
commit b37921d0b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 10 deletions

View File

@ -287,14 +287,7 @@ abstract class SQLConditionalExpression extends SQLExpression
continue;
}
if (preg_match('/AS\s+(?:"[^"]+"|[A-Z0-9_]+)\s*$/i', $join ?? '')) {
// custom aliases override the ones defined through array keys
// this is only meant to keep backward compatibility with SS <= 4.3,
// to be removed in SS5
continue;
}
$trimmedAlias = trim($alias ?? '', '"');
$trimmedAlias = trim($alias, '"');
if ($trimmedAlias !== trim($join ?? '', '"')) {
$joins[$alias] = "{$join} AS \"{$trimmedAlias}\"";

View File

@ -814,15 +814,18 @@ class SQLSelectTest extends SapphireTest
$sql
);
// This feature is a bug that used to exist in SS4 and was removed in SS5
// so now we test it does not exist and we end up with incorrect SQL because of that
// In SS4 the "explicitAlias" would be ignored
$query = SQLSelect::create('*', [
'MyTableAlias' => '"MyTable"',
'ignoredAlias' => ', (SELECT * FROM "MyTable" where "something" = "whatever") as "CrossJoin"'
'explicitAlias' => ', (SELECT * FROM "MyTable" where "something" = "whatever") as "CrossJoin"'
]);
$sql = $query->sql();
$this->assertSQLEquals(
'SELECT * FROM "MyTable" AS "MyTableAlias" , ' .
'(SELECT * FROM "MyTable" where "something" = "whatever") as "CrossJoin"',
'(SELECT * FROM "MyTable" where "something" = "whatever") as "CrossJoin" AS "explicitAlias"',
$sql
);
}