Skip to content

Commit 332a628

Browse files
mpscholtenclaude
andcommitted
Fix empty password in DATABASE_URL by patching postgresql-connection-string
Instead of normalizing the connection string in IHP code, use our upstream fix for the postgresql-connection-string parser which handles user:@host (empty password) correctly. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent adf54ca commit 332a628

File tree

3 files changed

+6
-17
lines changed

3 files changed

+6
-17
lines changed

NixSupport/overlay.nix

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,11 @@ let
9191
url = "https://hackage.haskell.org/package/postgresql-binary-0.15/postgresql-binary-0.15.tar.gz";
9292
sha256 = "11ysy91rsvdx9n7cjpyhp23ikv3h9b40k6rdggykhjkdv7vdvhj3";
9393
}) {}));
94+
# Patched to fix parsing of empty password in URI format (user:@host)
95+
# See: https://github.com/nikita-volkov/postgresql-connection-string/pull/3
9496
postgresql-connection-string = fastBuild (self.callCabal2nix "postgresql-connection-string" (builtins.fetchTarball {
95-
url = "https://hackage.haskell.org/package/postgresql-connection-string-0.1/postgresql-connection-string-0.1.tar.gz";
96-
sha256 = "071m8xzqak2b0l27zplfknsdq8x91k0iwimqikszdvdcj6mp1c6r";
97+
url = "https://github.com/mpscholten/postgresql-connection-string/archive/bb9bfb8cfff39e0e87aa24208d0e34a0cefb13cc.tar.gz";
98+
sha256 = "1jw3ka11anvx9prr5iliqwi42h5jlwbq8i0xlarzq2hgg3sc0sqp";
9799
}) {});
98100

99101
hasql = final.haskell.lib.dontCheck (final.haskell.lib.doJailbreak (fastBuild (self.callCabal2nix "hasql" (builtins.fetchTarball {

ihp-datasync/IHP/DataSync/Hasql.hs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import qualified Hasql.Connection as Hasql
1111
import qualified Hasql.Connection.Settings as HasqlSettings
1212
import qualified Hasql.Session as Session
1313
import qualified Hasql.Errors as Hasql
14-
import qualified Data.Text as Text
1514

1615
-- | Run a composed Session against the pool. Throws 'Hasql.Pool.UsageError' on failure.
1716
runSession :: Hasql.Pool.Pool -> Session.Session a -> IO a
@@ -38,13 +37,7 @@ runSessionOnConnection conn session = do
3837
-- action completes (normally or via exception).
3938
withDedicatedConnection :: ByteString -> (Hasql.Connection -> IO a) -> IO a
4039
withDedicatedConnection databaseUrl action = do
41-
-- Normalize for hasql's connection string parser:
42-
-- 1. postgres:// → postgresql://
43-
-- 2. Strip empty password (user:@host) → (user@host) — parser chokes on empty password
44-
let hasqlDatabaseUrl = cs databaseUrl
45-
|> Text.replace "postgres://" "postgresql://"
46-
|> Text.replace ":@" "@"
47-
connResult <- Hasql.acquire (HasqlSettings.connectionString hasqlDatabaseUrl)
40+
connResult <- Hasql.acquire (HasqlSettings.connectionString (cs databaseUrl))
4841
case connResult of
4942
Right conn -> action conn `Exception.finally` Hasql.release conn
5043
Left err -> error (Hasql.toDetailedText err)

ihp/IHP/ModelSupport.hs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,8 @@ createModelContext idleTime maxConnections databaseUrl logger = do
103103
-- HASQL_IDLE_TIME: seconds before idle connection is closed (default: 600 = 10 min)
104104
hasqlPoolSize :: Maybe Int <- envOrNothing "HASQL_POOL_SIZE"
105105
hasqlIdleTime :: Maybe Int <- envOrNothing "HASQL_IDLE_TIME"
106-
-- Normalize for hasql's connection string parser:
107-
-- 1. postgres:// → postgresql://
108-
-- 2. Strip empty password (user:@host) → (user@host) — parser chokes on empty password
109-
let hasqlDatabaseUrl = cs databaseUrl
110-
|> Text.replace "postgres://" "postgresql://"
111-
|> Text.replace ":@" "@"
112106
let hasqlPoolSettings =
113-
[ HasqlPoolConfig.staticConnectionSettings (HasqlSettings.connectionString hasqlDatabaseUrl)
107+
[ HasqlPoolConfig.staticConnectionSettings (HasqlSettings.connectionString (cs databaseUrl))
114108
]
115109
<> maybe [] (\size -> [HasqlPoolConfig.size size]) hasqlPoolSize
116110
<> maybe [] (\idle -> [HasqlPoolConfig.idlenessTimeout (fromIntegral idle)]) hasqlIdleTime

0 commit comments

Comments
 (0)