Thursday, December 22, 2016

Re: Inconsistent json_encode() behaviors regarding empty (sub)strings

2016-12-22 9:20 GMT+03:00 Kay Zheng <l04m33@gmail.com>:
> Hi folks,
>
> I was trying out the new channel APIs, and found a little glitch in
> the built-in function json_encode():
>
> call assert_equal('', 'a'[1:0]) " pass
> call assert_equal('""', json_encode('')) "pass
> call assert_equal('""', json_encode('a'[1:0])) " fail,
> json_encode(...) returns 'null'
>
> I failed to see any content about the sub-string syntax str[a:b] in
> the documents, but it seems legit for sub-lists, so I've been using it
> all over my code, until encode_json('a'[1:0]) gave me 'null' as a
> result.
>
> I was running Vim version 8.0.134. Is this a bug?

This kind of failure is observed for NULL strings (e.g. like returned
by test_null_string()). Given that NULL strings are an optimization
for empty strings I consider this a bug. Neovim does not have it:
https://github.com/neovim/neovim/blob/aa4ef8966c12a6bd51d31ce32618e9844053aa04/test/functional/eval/json_functions_spec.lua#L763-L765,
https://github.com/neovim/neovim/blob/aa4ef8966c12a6bd51d31ce32618e9844053aa04/test/unit/eval/tricks_spec.lua#L21-L34.

>
> Regards,
> Kay. Z
>
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: