Mercurial > dovecot > core-2.2
changeset 18579:363397c3701e
lib-fts: fts-tokenizer-address didn't reset state properly when input ended.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 09 May 2015 13:46:37 +0300 |
parents | eff53aa9cb58 |
children | 2dca6925bd88 |
files | src/lib-fts/fts-tokenizer-address.c src/lib-fts/test-fts-tokenizer.c |
diffstat | 2 files changed, 22 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-fts/fts-tokenizer-address.c Sat May 09 13:31:14 2015 +0300 +++ b/src/lib-fts/fts-tokenizer-address.c Sat May 09 13:46:37 2015 +0300 @@ -217,12 +217,19 @@ /* end of data, output lingering tokens. first the parents data, then possibly our token, if complete enough */ if (size == 0) { + if (tok->state == EMAIL_ADDRESS_PARSER_STATE_DOMAIN && + domain_is_empty(tok)) { + /* user@ without domain - reset state */ + str_truncate(tok->last_word, 0); + tok->state = EMAIL_ADDRESS_PARSER_STATE_NONE; + } + if (fts_tokenizer_address_parent_data(tok, token_r)) return 1; - if (tok->state == EMAIL_ADDRESS_PARSER_STATE_DOMAIN && - !domain_is_empty(tok)) + if (tok->state == EMAIL_ADDRESS_PARSER_STATE_DOMAIN) return fts_tokenizer_address_current_token(tok, token_r); + tok->state = EMAIL_ADDRESS_PARSER_STATE_NONE; } /* 1) regular input data OR
--- a/src/lib-fts/test-fts-tokenizer.c Sat May 09 13:31:14 2015 +0300 +++ b/src/lib-fts/test-fts-tokenizer.c Sat May 09 13:46:37 2015 +0300 @@ -554,6 +554,19 @@ eopp++; } test_assert(*eopp == NULL); + + test_assert(fts_tokenizer_next(tok, (const void *)"foo", 3, &token) == 0); + test_assert(fts_tokenizer_next(tok, NULL, 0, &token) > 0); + test_assert(fts_tokenizer_next(tok, NULL, 0, &token) == 0); + + test_assert(fts_tokenizer_next(tok, (const void *)"bar@baz", 7, &token) == 0); + test_assert(fts_tokenizer_next(tok, NULL, 0, &token) > 0); + test_assert(fts_tokenizer_next(tok, NULL, 0, &token) == 0); + + test_assert(fts_tokenizer_next(tok, (const void *)"foo@", 4, &token) == 0); + test_assert(fts_tokenizer_next(tok, NULL, 0, &token) > 0); + test_assert(fts_tokenizer_next(tok, NULL, 0, &token) == 0); + fts_tokenizer_unref(&tok); fts_tokenizer_unref(&gen_tok); fts_tokenizers_deinit();