killme2008 / killme2008/aviatorscript
表达式有\u等字符串编译报错
- Dominant language
- Java
- Stars
- 5.2k
- Forks
- 906
- PR merge metrics
- No merged PRs in 30d
Description
## 问题
我想注册一个函数 来实现**自定义**的正则匹配逻辑,函数是这样的:
```java
/**
* 正则匹配
*
* @param str 字符串
* @param reg 正则表达式
* @param allMatches 是否全文匹配
* @return 是否匹配
*/
public static boolean matchPattern(String str, String reg, boolean allMatches) {
if (StringUtils.isAnyEmpty(str, reg)) {
return false;
}
Matcher matcher = Pattern.compile(reg).matcher(str);
if (allMatches) {
return matcher.matches();
} else {
return matcher.find();
}
}
```
当使用aviator表达式编译时 正则中的一些转义会抛出不支持的异常 比如这个表达式
```
return matchPattern('很好', '[\u4e00-\u9fa5]{0,4}'); // 0-4个中文字符
```
其中\u会被解析器抛出无法识别异常
## 思路
请教下:如果移除源码中的 throw逻辑 ,可能会有哪些影响呢
`com/googlecode/aviator/lexer/ExpressionLexer.java:394`
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in com/googlecode/aviator/lexer/ExpressionLexer.java around line 394 and reproduce compilation of the shown matchPattern expression containing a \u escape. Trace why the lexer rejects it before deciding whether the throw logic should change. Done means the intended expression compiles without breaking existing escape handling, with the behavior verified by an appropriate regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100