Skip to content

Commit e57e017

Browse files
[REGRESSION] Prepend slash to path if needed (#91)
Prepend slash to path if needed Signed-off-by: Levko Kravets <levko.ne@gmail.com> Signed-off-by: Levko Kravets <levko.ne@gmail.com>
1 parent cc2cb62 commit e57e017

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

lib/DBSQLClient.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ import PlainHttpAuthentication from './connection/auth/PlainHttpAuthentication';
2121
import IDBSQLLogger, { LogLevel } from './contracts/IDBSQLLogger';
2222
import DBSQLLogger from './DBSQLLogger';
2323

24+
function prependSlash(str: string): string {
25+
if (str.length > 0 && str.charAt(0) !== '/') {
26+
return `/${str}`;
27+
}
28+
return str;
29+
}
30+
2431
function getInitialNamespaceOptions(catalogName?: string, schemaName?: string) {
2532
if (!catalogName && !schemaName) {
2633
return {};
@@ -61,11 +68,12 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient {
6168
}
6269

6370
private getConnectionOptions(options: ConnectionOptions): IConnectionOptions {
64-
const { host, port, token, clientId, ...otherOptions } = options;
71+
const { host, port, path, token, clientId, ...otherOptions } = options;
6572
return {
6673
host,
6774
port: port || 443,
6875
options: {
76+
path: prependSlash(path),
6977
https: true,
7078
...otherOptions,
7179
},

tests/unit/DBSQLClient.test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,42 @@ describe('DBSQLClient.connect', () => {
3131
token: 'dapi********************************',
3232
};
3333

34+
it('should prepend "/" to path if it is missing', async () => {
35+
const client = new DBSQLClient();
36+
client.thrift = {
37+
createClient() {},
38+
};
39+
const connectionProvider = ConnectionProviderMock();
40+
41+
const path = 'example/path';
42+
43+
client.connectionProvider = connectionProvider;
44+
await client.connect({
45+
...options,
46+
path,
47+
});
48+
49+
expect(connectionProvider.options.options.path).to.equal(`/${path}`);
50+
});
51+
52+
it('should not prepend "/" to path if it is already available', async () => {
53+
const client = new DBSQLClient();
54+
client.thrift = {
55+
createClient() {},
56+
};
57+
const connectionProvider = ConnectionProviderMock();
58+
59+
const path = '/example/path';
60+
61+
client.connectionProvider = connectionProvider;
62+
await client.connect({
63+
...options,
64+
path,
65+
});
66+
67+
expect(connectionProvider.options.options.path).to.equal(path);
68+
});
69+
3470
it('should set nosasl authenticator by default', async () => {
3571
const client = new DBSQLClient();
3672
const connectionProvider = ConnectionProviderMock();

0 commit comments

Comments
 (0)