Skip to content

Commit

Permalink
fix bug whereby multi-byte utf8 at end of string incorrectly treated …
Browse files Browse the repository at this point in the history
…as malformed
  • Loading branch information
liquidaty committed Dec 26, 2023
1 parent 93d349e commit e5203f8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ test: ${TESTS}
test-prop:
EXE=${BUILD_DIR}/bin/zsv_prop${EXE} make -C prop test

test-echo : test-echo1 test-echo-overwrite test-echo-eol test-echo-overwrite-csv
test-echo : test-echo1 test-echo-overwrite test-echo-eol test-echo-overwrite-csv test-echo-chars

test-echo1: ${BUILD_DIR}/bin/zsv_echo${EXE}
@${TEST_INIT}
Expand All @@ -114,6 +114,11 @@ test-echo-eol-%: ${BUILD_DIR}/bin/zsv_echo${EXE}
@${PREFIX} $< ${TEST_DATA_DIR}/test/no-eol-$*.csv ${REDIRECT} ${TMP_DIR}/$@.out
@${CMP} ${TMP_DIR}/$@.out expected/$@.out && ${TEST_PASS} || ${TEST_FAIL}

test-echo-chars: ${BUILD_DIR}/bin/zsv_echo${EXE}
@${TEST_INIT}
@${PREFIX} echo '東京都' | $< -u '?' ${REDIRECT} ${TMP_DIR}/$@.out
@${CMP} ${TMP_DIR}/$@.out expected/$@.out && ${TEST_PASS} || ${TEST_FAIL}

test-echo-overwrite: ${BUILD_DIR}/bin/zsv_echo${EXE}
@${TEST_INIT}
@${PREFIX} $< ${TEST_DATA_DIR}/loans_1.csv --overwrite 'sqlite3://${TEST_DATA_DIR}/loans_1-overwrite.db?sql=select row,col,value from overwrites order by row,col' ${REDIRECT} ${TMP_DIR}/$@.out
Expand Down
1 change: 1 addition & 0 deletions app/test/expected/test-echo-chars.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
東京都
1 change: 1 addition & 0 deletions app/zsv_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define ZSV_MAIN_NO_OPTIONS_FUNC1(x) zsv_ ## x ## _main_no_options

struct zsv_opts;
struct zsv_prop_handler;

/* macros for commands that use common zsv parsing */
#define ZSV_MAIN_FUNC(x) ZSV_MAIN_FUNC1(x)
Expand Down
2 changes: 1 addition & 1 deletion src/zsv_strencode.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ size_t zsv_strencode(unsigned char *s, size_t n, unsigned char replace,
clen = ZSV_UTF8_CHARLEN(s[i2]);
if(LIKELY(clen == 1))
s[new_len++] = s[i2];
else if(UNLIKELY(clen < 0) || UNLIKELY(i2 + clen >= n)) {
else if(UNLIKELY(clen < 0) || UNLIKELY(i2 + clen > n)) {
if(malformed_handler)
malformed_handler(handler_ctx, s, n, new_len);
if(replace)
Expand Down

0 comments on commit e5203f8

Please sign in to comment.