mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix bug
This commit is contained in:
parent
89a3acfa88
commit
eda8bdc27a
@ -11,6 +11,7 @@
|
||||
* 【core 】 增加NanoId
|
||||
* 【core 】 MapBuilder增加put方法(pr#367@Gitee)
|
||||
* 【core 】 StrUtil.insert支持负数index
|
||||
* 【core 】 Calculator类支持取模运算(issue#I40DUW@Gitee)
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【core 】 修复FileUtil.normalize处理上级路径的问题(issue#I3YPEH@Gitee)
|
||||
@ -18,6 +19,7 @@
|
||||
* 【core 】 修复FastDatePrinter歧义问题(pr#366@Gitee)
|
||||
* 【core 】 修复DateUtil.format格式化Instant报错问题(issue#I40CY2@Gitee)
|
||||
* 【core 】 修复StrUtil.toUnderlineCase大写问题(issue#I40CGS@Gitee)
|
||||
* 【jwt 】 修复JWT.validate报错问题(issue#I40MR2@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -144,7 +144,7 @@ public class Calculator {
|
||||
* @return 是否为算术符号
|
||||
*/
|
||||
private boolean isOperator(char c) {
|
||||
return c == '+' || c == '-' || c == '*' || c == '/' || c == '(' || c == ')';
|
||||
return c == '+' || c == '-' || c == '*' || c == '/' || c == '(' || c == ')' || c == '%';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -155,7 +155,17 @@ public class Calculator {
|
||||
* @return 优先级
|
||||
*/
|
||||
public boolean compare(char cur, char peek) {// 如果是peek优先级高于cur,返回true,默认都是peek优先级要低
|
||||
return operatPriority[(peek) - 40] >= operatPriority[(cur) - 40];
|
||||
final int offset = 40;
|
||||
if(cur == '%'){
|
||||
// %优先级最高
|
||||
cur = 47;
|
||||
}
|
||||
if(peek == '%'){
|
||||
// %优先级最高
|
||||
peek = 47;
|
||||
}
|
||||
|
||||
return operatPriority[(peek) - offset] >= operatPriority[(cur) - offset];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,7 +173,7 @@ public class Calculator {
|
||||
*
|
||||
* @param firstValue 第一个值
|
||||
* @param secondValue 第二个值
|
||||
* @param currentOp 算数符,只支持'+'、'-'、'*'、'/'
|
||||
* @param currentOp 算数符,只支持'+'、'-'、'*'、'/'、'%'
|
||||
* @return 结果
|
||||
*/
|
||||
private BigDecimal calculate(String firstValue, String secondValue, char currentOp) {
|
||||
@ -181,6 +191,9 @@ public class Calculator {
|
||||
case '/':
|
||||
result = NumberUtil.div(firstValue, secondValue);
|
||||
break;
|
||||
case '%':
|
||||
result = NumberUtil.toBigDecimal(firstValue).remainder(NumberUtil.toBigDecimal(secondValue));
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected value: " + currentOp);
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable {
|
||||
if(index < 0){
|
||||
index = this.position + index;
|
||||
}
|
||||
if ((index < 0) || (index > this.position)) {
|
||||
if ((index < 0)) {
|
||||
throw new StringIndexOutOfBoundsException(index);
|
||||
}
|
||||
|
||||
@ -221,7 +221,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable {
|
||||
if(index < 0){
|
||||
index = this.position + index;
|
||||
}
|
||||
if ((index < 0) || (index > this.position)) {
|
||||
if ((index < 0)) {
|
||||
throw new StringIndexOutOfBoundsException(index);
|
||||
}
|
||||
|
||||
@ -252,7 +252,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable {
|
||||
if(index < 0){
|
||||
index = this.position + index;
|
||||
}
|
||||
if ((index < 0) || (index > this.position)) {
|
||||
if ((index < 0)) {
|
||||
throw new StringIndexOutOfBoundsException(index);
|
||||
}
|
||||
|
||||
@ -309,7 +309,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable {
|
||||
if(index < 0){
|
||||
index = this.position + index;
|
||||
}
|
||||
if ((index < 0) || (index > this.position)) {
|
||||
if ((index < 0)) {
|
||||
throw new StringIndexOutOfBoundsException(index);
|
||||
}
|
||||
|
||||
|
@ -22,4 +22,10 @@ public class CalculatorTest {
|
||||
final double conversion = Calculator.conversion("1");
|
||||
Assert.assertEquals(1, conversion, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void conversationTest4(){
|
||||
final double conversion = Calculator.conversion("(88*66/23)%26+45%9");
|
||||
Assert.assertEquals((88D * 66 / 23) % 26, conversion, 2);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import cn.hutool.core.lang.Console;
|
||||
*
|
||||
*/
|
||||
public class StrBuilderTest {
|
||||
|
||||
|
||||
/**
|
||||
* StrBuilder的性能测试
|
||||
*/
|
||||
@ -28,7 +28,7 @@ public class StrBuilderTest {
|
||||
builder.reset();
|
||||
}
|
||||
Console.log(timer.interval());
|
||||
|
||||
|
||||
timer.restart();
|
||||
StringBuilder b2 = new StringBuilder();
|
||||
for(int i =0; i< 1000000; i++) {
|
||||
@ -37,14 +37,14 @@ public class StrBuilderTest {
|
||||
}
|
||||
Console.log(timer.interval());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void appendTest() {
|
||||
StrBuilder builder = StrBuilder.create();
|
||||
builder.append("aaa").append("你好").append('r');
|
||||
Assert.assertEquals("aaa你好r", builder.toString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void insertTest() {
|
||||
StrBuilder builder = StrBuilder.create(1);
|
||||
@ -52,7 +52,7 @@ public class StrBuilderTest {
|
||||
builder.insert(3, "数据插入");
|
||||
Assert.assertEquals("aaa数据插入你好r", builder.toString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void insertTest2() {
|
||||
StrBuilder builder = StrBuilder.create(1);
|
||||
@ -60,7 +60,7 @@ public class StrBuilderTest {
|
||||
builder.insert(8, "数据插入");
|
||||
Assert.assertEquals("aaa你好r 数据插入", builder.toString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void resetTest() {
|
||||
StrBuilder builder = StrBuilder.create(1);
|
||||
@ -69,7 +69,7 @@ public class StrBuilderTest {
|
||||
builder.reset();
|
||||
Assert.assertEquals("", builder.toString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void resetTest2() {
|
||||
StrBuilder builder = StrBuilder.create(1);
|
||||
@ -79,7 +79,7 @@ public class StrBuilderTest {
|
||||
builder.append("bbb".toCharArray());
|
||||
Assert.assertEquals("bbb", builder.toString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void appendObjectTest() {
|
||||
StrBuilder builder = StrBuilder.create(1);
|
||||
@ -100,7 +100,6 @@ public class StrBuilderTest {
|
||||
public void delTest2() {
|
||||
// 删除中间部分测试
|
||||
StrBuilder strBuilder = new StrBuilder("ABCDEFG");
|
||||
int length = strBuilder.length();
|
||||
StrBuilder builder = strBuilder.del(2,6);
|
||||
Assert.assertEquals("ABG", builder.toString());
|
||||
}
|
||||
|
@ -352,7 +352,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
|
||||
// 校验时间字段
|
||||
try {
|
||||
JWTValidator.of(tokens.get(2)).validateDate(DateUtil.date(), leeway);
|
||||
JWTValidator.of(this).validateDate(DateUtil.date(), leeway);
|
||||
} catch (ValidateException e) {
|
||||
return false;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package cn.hutool.jwt;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.exceptions.ValidateException;
|
||||
import cn.hutool.jwt.signers.JWTSignerUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class JWTValidatorTest {
|
||||
@ -60,4 +61,12 @@ public class JWTValidatorTest {
|
||||
// 验证算法
|
||||
JWTValidator.of(token).validateAlgorithm(JWTSignerUtil.hs256("123456".getBytes()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateTest(){
|
||||
String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJNb0xpIiwiZXhwIjoxNjI0OTU4MDk0NTI4LCJpYXQiOjE2MjQ5NTgwMzQ1MjAsInVzZXIiOiJ1c2VyIn0.L0uB38p9sZrivbmP0VlDe--j_11YUXTu3TfHhfQhRKc";
|
||||
byte[] key = "1234567890".getBytes();
|
||||
boolean validate = JWT.of(token).setKey(key).validate(0);
|
||||
Assert.assertFalse(validate);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user