[1/3] fix broken SQL query that always failed

Message ID 20210217032854.245535-1-eschwartz@archlinux.org
State New
Headers show
Series [1/3] fix broken SQL query that always failed | expand

Commit Message

Eli Schwartz Feb. 17, 2021, 3:28 a.m. UTC
Due to missing whitespace at the end of strings during joining, we ended
up with the query fragment

"DelTS IS NULLAND NOT PinnedTS"

which should be

"DelTS IS NULL AND NOT PinnedTS"

So the check for pinned comments > 5 likely always failed.

In php 7, a completely broken query that raises exceptions in the
database engine was silently ignored... in php 8, it raises

Uncaught PDOException: SQLSTATE[HY000]: General error: 1 near "PinnedTS": syntax error in <file>

and aborts the page building. End result: users with permission to pin
comments cannot see any comments, or indeed page content below the first
comment header

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
---
 web/lib/pkgbasefuncs.inc.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Lukas Fleischer Feb. 20, 2021, 4:33 p.m. UTC | #1
Merged all three patches (and closed merge request on GitLab). Thanks!
Jelle van der Waa Feb. 20, 2021, 5:58 p.m. UTC | #2
On 20/02/2021 17:33, Lukas Fleischer via aur-dev wrote:
> Merged all three patches (and closed merge request on GitLab). Thanks!
> 

Thanks for merging, will this be available in the live branch soon?

Thanks in advance,

Jelle

Patch

diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php
index a4925891..4c8abba7 100644
--- a/web/lib/pkgbasefuncs.inc.php
+++ b/web/lib/pkgbasefuncs.inc.php
@@ -21,7 +21,7 @@  function pkgbase_comments_count($base_id, $include_deleted, $only_pinned=false)
 	$q = "SELECT COUNT(*) FROM PackageComments ";
 	$q.= "WHERE PackageBaseID = " . $base_id . " ";
 	if (!$include_deleted) {
-		$q.= "AND DelTS IS NULL";
+		$q.= "AND DelTS IS NULL ";
 	}
 	if ($only_pinned) {
 		$q.= "AND NOT PinnedTS = 0";