Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix -u option bug whereby multibyte utf8 at end of string incorrectly treated as malformed (#145) #145

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}/[email protected]
@${CMP} ${TMP_DIR}/[email protected] expected/[email protected] && ${TEST_PASS} || ${TEST_FAIL}

test-echo-chars: ${BUILD_DIR}/bin/zsv_echo${EXE}
@${TEST_INIT}
@${PREFIX} echo '東京都' | $< -u '?' ${REDIRECT} ${TMP_DIR}/[email protected]
@${CMP} ${TMP_DIR}/[email protected] expected/[email protected] && ${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}/[email protected]
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