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

Empty output from encode() #49

Closed
tomyun opened this issue Jun 14, 2021 · 3 comments · Fixed by #50
Closed

Empty output from encode() #49

tomyun opened this issue Jun 14, 2021 · 3 comments · Fixed by #50

Comments

@tomyun
Copy link

tomyun commented Jun 14, 2021

julia> encode("", "shift_jisx0213")
UInt8[]

This should have provided the same result as "sjis" encoding.

julia> encode("", "sjis")
2-element Vector{UInt8}:
 0x83
 0x4e
@nalimilan
Copy link
Member

Thanks for the report. I suspect this is an issue in GNU libiconv, as it doesn't seem to write anything to the output buffer. Would you file an issue in their bug tracker?

@tomyun
Copy link
Author

tomyun commented Jun 19, 2021

While I don't quite understand iconv behavior either (i.e. compared to "sjis" encoding which just works), it's also clearly stated that the output buffer should be explicitly flushed out by caller to prevent partial results like this go missing.

In each series of calls to iconv(), the last should be one with inbuf or *inbuf equal to NULL, in order to flush out any partially converted input.

With that, it seems like iconv_reset!() should be called somewhere like in flush() for StringEncodings.jl to properly handle this kind of case.

Related discussion in other language can be found here if needed: racket/racket#3876

@nalimilan
Copy link
Member

Woops, indeed there was a missing operation after closing the stream. I'm not sure why the existing tests didn't catch this, given that I've checked that they cover a case where final bytes are written in a stateful encoding. Anyway, see #50.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants