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]StringSchema正则校验format字符串pattern not match, expect %, but %s错误 #770

Closed
ai3forever opened this issue Sep 15, 2022 · 2 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@ai3forever
Copy link

ai3forever commented Sep 15, 2022

问题描述

简要描述您碰到的问题。

环境信息

请填写以下信息:

  • OS信息: [e.g.:任何版本]
  • JDK信息: [e.g.:任何版本]
  • 版本信息:[e.g.:任何版本]

重现步骤

String类型校验正则失败时异常
查看StringSchema.java源码,发现format字符串错误%应该为%s,后面有附加截图

//可在此输入示例代码

public class MyTest {

    public static void main(String[] args) throws JsonProcessingException {
        String schemaStr = "{\n" +
                "  \"required\":[\"memory\"],\n" +
                "  \"properties\": {\n" +
                "    \"memory\": {\n" +
                "      \"type\":\"string\",\n" +
                "      \"pattern\": \"^([1-9][0-9]{0,1}|100)$\"\n" +
                "    }\n" +
                "  }\n" +
                "}";
        JSONObject js = JSONObject.of("memory", "101");
        JSONSchema jsonSchema = JSONSchema.parseSchema(schemaStr);
        ValidateResult vr = jsonSchema.validate(js);
        System.out.println(vr.isSuccess() + "====" + vr.getMessage());
    }
}

期待的正确结果

正常获取到message信息

相关日志输出

Exception in thread "main" java.util.FormatFlagsConversionMismatchException: Conversion = b, Flags =
at java.base/java.util.Formatter$FormatSpecifier.failMismatch(Formatter.java:4422)
at java.base/java.util.Formatter$FormatSpecifier.checkBadFlags(Formatter.java:3151)
at java.base/java.util.Formatter$FormatSpecifier.checkGeneral(Formatter.java:3109)
at java.base/java.util.Formatter$FormatSpecifier.(Formatter.java:2870)
at java.base/java.util.Formatter.parse(Formatter.java:2713)
at java.base/java.util.Formatter.format(Formatter.java:2655)
at java.base/java.util.Formatter.format(Formatter.java:2609)
at java.base/java.lang.String.format(String.java:2897)
at com.alibaba.fastjson2.schema.ValidateResult.getMessage(ValidateResult.java:42)
at com.alibaba.fastjson2.schema.ValidateResult.getMessage(ValidateResult.java:44)
at com.lixiang.licloud.oam.MyTest.main(MyTest.java:31)

附加信息

image

@ai3forever ai3forever added the bug Something isn't working label Sep 15, 2022
@wenshao wenshao added this to the 2.0.14 milestone Sep 15, 2022
@wenshao
Copy link
Member

wenshao commented Sep 15, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.14-SNAPSHOT/
问题已修复,请用2.0.14-SNAPSHOT版本帮忙验证,2.0.14版本预计在9月17日前发布

@wenshao
Copy link
Member

wenshao commented Sep 16, 2022

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

@wenshao wenshao closed this as completed Sep 16, 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 fixed
Projects
None yet
Development

No branches or pull requests

2 participants