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

代码注释编译异常 #311

Open
cying314 opened this issue Dec 28, 2023 · 4 comments
Open

代码注释编译异常 #311

cying314 opened this issue Dec 28, 2023 · 4 comments

Comments

@cying314
Copy link

用/** **/注释代码,注释中出现“2倍”字样时,报错编译异常:NumberFormatException: For input string: "2倍"。
复现表达式:
/** 2倍 **/

@DQinYuan
Copy link
Collaborator

版本是什么?能给出复现代码吗? 我自测没发现这个问题

    @Test
    public void commentTest() throws Exception {
        String express = "/** 2 倍 **/ return 10";
        ExpressRunner runner = new ExpressRunner(false, true);
        DefaultContext<String, Object> context = new DefaultContext<>();
        Object res = runner.execute(express, context, null, true, true);
        System.out.println(res);
    }

@cying314
Copy link
Author

cying314 commented Jan 21, 2024

版本是什么?能给出复现代码吗?我自测没发现这个问题

    @Test
    public void commentTest() throws Exception {
        String express = "/** 2 倍 **/ return 10";
        ExpressRunner runner = new ExpressRunner(false, true);
        DefaultContext<String, Object> context = new DefaultContext<>();
        Object res = runner.execute(express, context, null, true, true);
        System.out.println(res);
    }

我看到你的代码片段里面,2后面是打了空格的,如果去掉空格呢?
最小复现代码就是/** 2倍 **/其余什么都不打就会报这个错。
涉及版本是3.3.1。
我们当时是将部分业务文档以注释方式打在的生产环境中供客户查看,除了"2倍"被当成数字错误解析外,还发现有很多类似的特殊字符注释会被错误的解析,最终解决方案是用正则匹配去掉/****/内容,再去调表达式解析

@MoonNigth
Copy link

版本:3.3.2
确实有编译问题,会把“2倍”当作数字取解析,导致报错

    @Test
    public void zsTest() throws Exception {
        ExpressRunner runner = new ExpressRunner(true, false);
        DefaultContext<String, Object> context = new DefaultContext<String, Object>();
        // 定义表达式
        String express = "/** 2倍 **/ 1+1";
        System.out.println("表达式结果:" + runner.execute(express, context, null, true, true));

    }

图片

@DQinYuan
Copy link
Collaborator

@MoonNigth @cying314 确实有问题,我拉个分支修一下. 我之前用例里多了个空格, 导致当成数字解析通过了

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

No branches or pull requests

3 participants