Skip to content

Commit dd64549

Browse files
Support special chars in password as part of url string
1 parent f7cd658 commit dd64549

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/drivers/utilities.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ export function validateConfiguration(config: SQLiteCloudConfig): SQLiteCloudCon
200200
if (!config.connectionString) {
201201
// build connection string from configuration, values are already validated
202202
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
203-
config.connectionString = `sqlitecloud://${config.username}:${config.password}@${config.host}:${config.port}/${config.database}`
203+
config.connectionString = `sqlitecloud://${encodeURIComponent(config.username)}:${encodeURIComponent(config.password)}@${config.host}:${config.port}/${
204+
config.database
205+
}`
204206
}
205207

206208
return config
@@ -223,8 +225,8 @@ export function parseConnectionString(connectionString: string): SQLiteCloudConf
223225
})
224226

225227
const config: SQLiteCloudConfig = {
226-
username: url.username,
227-
password: url.password,
228+
username: decodeURIComponent(url.username),
229+
password: decodeURIComponent(url.password),
228230
host: url.hostname,
229231
port: url.port ? parseInt(url.port) : undefined,
230232
...options

test/utilities.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,17 @@ describe('parseConnectionString', () => {
165165
database: 'database'
166166
})
167167
})
168+
169+
it('should handle url encoded password', () => {
170+
const connectionString = 'sqlitecloud://user:pass%25word@host:1234/database'
171+
const config = parseConnectionString(connectionString)
172+
173+
expect(config).toEqual({
174+
username: 'user',
175+
password: 'pass%word',
176+
host: 'host',
177+
port: 1234,
178+
database: 'database'
179+
})
180+
})
168181
})

0 commit comments

Comments
 (0)