-
-
Notifications
You must be signed in to change notification settings - Fork 709
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
Term::text() doesn't panic if the term isn't valid UTF-8 #138
Comments
Good point. Will fix |
Why not return an error and let the caller decide whether to panic or not? |
@BurntSushi Not sure what is the best here. Let me list the case where this can panic... String terms are supposedly built by passing a a) the data is corrupted. I chose (I think you have the same policy in So we are left with c) and d). I just marked as What do you guys think? Should I return a Result for the case |
@fulmicoton Thanks for explaining! I think (a) and (b) would be fine reasons to panic. You're right that the (c) and (d) are trickier. I don't know what the right answer is. One possible alternative is that you leave |
Just to make it clear. d) has been ruled out. I am wondering if user might misunderstand the semantics of I will let like that for the moment and fix the API eventually to had a typed version of |
hi @fulmicoton my _id is [u8] but I need it to index for delete. if set but when search has panic .how to solve it? |
@ansjun Tantivy does not support indexed As a workaround, could you encode your "_id" in base64 ? |
Yes, that's the only way right now thx |
There's a problem with the implementation of the following method:
(https://github.com/tantivy-search/tantivy/blob/0dad02791c74e572ec005abb1f75e3601bd25db5/src/schema/term.rs#L110-L118)
Unlike the comment suggests,
str::from_utf8_unchecked
does not panic if the passed value isn't valid UTF-8 (If it did, the function wouldn't beunsafe
). This is pretty bad as if it's invalid, the returned string would be invalid too and could cause a confusing error later on.The following implementation should make it behave correctly:
The text was updated successfully, but these errors were encountered: