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

[BUG] 不可见字符输出格式不对 #435

Closed
seefan opened this issue Jun 8, 2022 · 1 comment
Closed

[BUG] 不可见字符输出格式不对 #435

seefan opened this issue Jun 8, 2022 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@seefan
Copy link

seefan commented Jun 8, 2022

问题描述

对不可见字符没有处理,会引起异常
比如换行符现在可以转换成\n,但ascii为17的不可见字符没有处理,会引起异常。不是特定为17,是所有的不可见字符。

环境信息

请填写以下信息:

  • OS信息: linux
  • JDK信息: jdk1.8
  • 版本信息:Fastjson2 2.0.6

重现步骤

        char abc = 17;
        String str =
                "{\"test\": \"Pixel 民" + String.valueOf(abc) + "\n XL\"}";
        Object object = com.alibaba.fastjson2.JSON.parse(str);

        System.out.println(com.alibaba.fastjson.JSON.toJSONString(object, SerializerFeature.BrowserCompatible));
        System.out.println(com.alibaba.fastjson2.JSON.toJSONString(object, JSONWriter.Feature.BrowserCompatible));
        ObjectMapper objectMapper = new ObjectMapper();
        System.out.println(objectMapper.writeValueAsString(object));

        ////输出结果
       {"test":"Pixel \u6C11\u0011\n XL"}//中文被编码
       {"test":"Pixel 民�\n XL"}//abc没有被编码
       {"test":"Pixel 民\u0011\n XL"}//预期的结果
@seefan seefan added the bug Something isn't working label Jun 8, 2022
@wenshao wenshao added this to the 2.0.7 milestone Jun 8, 2022
@wenshao wenshao changed the title [BUG] [BUG] 不可见字符输出格式不对 Jun 9, 2022
@wenshao
Copy link
Member

wenshao commented Jun 11, 2022

https://github.com/alibaba/fastjson2/releases/tag/2.0.7
问题已经修复,请用新版本

@wenshao wenshao closed this as completed Jun 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants