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

How to handle unused tokens while decoding? #21

Open
0ndorio opened this issue Mar 5, 2019 · 1 comment
Open

How to handle unused tokens while decoding? #21

0ndorio opened this issue Mar 5, 2019 · 1 comment
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@0ndorio
Copy link
Contributor

0ndorio commented Mar 5, 2019

The port of additional test cases (#20) to fix issue #7 revealed a new question. The original test suite contained some cases marked as "illegal" which contain more tokens than actually required to restore the expected data type. Example: Decoding i12345e5:hellointo an integer.

How should FromBencode handle the case? Potential solutions I can think of:

  • silently drop them (as we do right now)
  • return an error variant which contains the unused tokens
  • add an additional default implementation next to from_bencode with stricter handling
@0ndorio 0ndorio added help wanted Extra attention is needed question Further information is requested labels Mar 5, 2019
@thequux
Copy link
Contributor

thequux commented Mar 5, 2019

I think the best solution is something like the last one, but we make from_bencode return a Result<(Self, &[u8]), Error> (where the &[u8] is what's left in the input string), and then have a from_bencode_complete that converts the case where there's something left into an error

I'm not firm on the naming; I'd also be OK with from_bencode_partial and from_bencode for the current behaviour and the new behaviour, respectively

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants