Skip to content

Commit 9dc3cec

Browse files
committed
Fix: trim whitespace from certain DSN fields (#189)
Trim whitespace from Cloud ID, User and Host field values before submitting these to the driver (WS is likely to be inserted if copy&pasting these values.) Also, rephrase the error message presented to the user in case the Cloud ID is incorrect. (cherry picked from commit c4b36bb)
1 parent f553b9a commit 9dc3cec

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

driver/connect.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -949,8 +949,7 @@ static BOOL decode_cloud_id(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)
949949
if (Curl_base64_decode(buff, &dec, &len) != CURLE_OK) {
950950
ERRH(dbc, "failed to decode B64 part of Cloud ID: [%zu] `" LWPDL "`.",
951951
attrs->cloud_id.cnt, LWSTR(&attrs->cloud_id));
952-
SET_HDIAG(dbc, SQL_STATE_HY000, "Invalid Base64 encoding in Cloud ID "
953-
"parameter", 0);
952+
SET_HDIAG(dbc, SQL_STATE_HY000, "Invalid Cloud ID parameter", 0);
954953
return FALSE;
955954
}
956955
DBGH(dbc, "Cloud ID decoded to: [%zu] `" LCPDL "`.", len, len, dec);

dsneditor/EsOdbcDsnEditor/DSNEditorForm.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,13 @@ private bool RebuildAndValidateDsn()
258258
// Basic Panel
259259
Builder["dsn"] = textName.Text;
260260
Builder["description"] = textDescription.Text;
261-
Builder["uid"] = textUsername.Text;
261+
// https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-put-user.html#security-api-put-user-path-params :
262+
// "Leading or trailing whitespace is not allowed." -> it is more likely that a user will insert a
263+
// (trailing) white space by mistake than intentionally trying to set it.
264+
Builder["uid"] = textUsername.Text.Trim();
262265
Builder["pwd"] = textPassword.Text;
263-
Builder["cloudid"] = "{" + textCloudID.Text.StripBraces() + "}";
264-
Builder["server"] = textHostname.Text;
266+
Builder["cloudid"] = "{" + textCloudID.Text.StripBraces().Trim() + "}";
267+
Builder["server"] = textHostname.Text.Trim();
265268
Builder["port"] = numericUpDownPort.Text;
266269

267270
// Security Panel

0 commit comments

Comments
 (0)