Skip to content

Commit 24c6e5c

Browse files
committed
Fix stripping trailing spaces for char -> binary conversions
Check the correct behaviour using proprietary libraries. More similar to leading stripping. Remove a very old FIXME in the code. Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
1 parent e668d71 commit 24c6e5c

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/ctlib/unittests/cs_convert.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ TEST_MAIN()
309309
/* spaces, tabs and initial "0x" are ignored */
310310
DO_TEST(CS_CHAR test[] = " \t \t0x616263";
311311
CS_CHAR test2[] = "abc", CS_CHAR_TYPE, test, 12, CS_BINARY_TYPE, 3, CS_SUCCEED, test2, 3);
312+
/* spaces and trailing tabs are ignored */
313+
DO_TEST(CS_CHAR test[] = "616263 \t ";
314+
CS_CHAR test2[] = "abc", CS_CHAR_TYPE, test, 9, CS_BINARY_TYPE, 3, CS_SUCCEED, test2, 3);
312315
/* odd number of characters */
313316
DO_TEST(CS_CHAR test[] = "61626";
314317
CS_CHAR test2[] = "\x06\x16\x26", CS_CHAR_TYPE, test, 5, CS_BINARY_TYPE, 3, CS_SUCCEED, test2, 3);

src/dblib/bcp.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,11 @@ _bcp_read_hostfile(DBPROCESS * dbproc, FILE * hostfile, bool *row_error, bool sk
13281328
if (collen == 0)
13291329
data_is_null = true;
13301330

1331+
/* To support empty strings and keep compatibility with older files empty strings
1332+
* are encoded as a single NUL byte. */
1333+
if (collen == 1 && coldata[0] == '\0')
1334+
collen = 0;
1335+
13311336
/*
13321337
* TODO:
13331338
* Dates are a problem. In theory, we should be able to read non-English dates, which

src/tds/convert.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,9 +2013,8 @@ tds_convert_to_binary(int srctype, const TDS_CHAR * src, TDS_UINT srclen, int de
20132013
srclen -= 2;
20142014
}
20152015

2016-
/* ignore trailing blanks and nulls */
2017-
/* FIXME is good to ignore null ?? */
2018-
while (srclen > 0 && (src[srclen - 1] == ' ' || src[srclen - 1] == '\0'))
2016+
/* ignore trailing spaces and tabs */
2017+
while (srclen > 0 && (src[srclen - 1] == ' ' || src[srclen - 1] == '\t'))
20192018
--srclen;
20202019

20212020
/* a binary string output will be half the length of */

0 commit comments

Comments
 (0)