mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix bug
This commit is contained in:
parent
89a3acfa88
commit
eda8bdc27a
@ -11,6 +11,7 @@
|
|||||||
* 【core 】 增加NanoId
|
* 【core 】 增加NanoId
|
||||||
* 【core 】 MapBuilder增加put方法(pr#367@Gitee)
|
* 【core 】 MapBuilder增加put方法(pr#367@Gitee)
|
||||||
* 【core 】 StrUtil.insert支持负数index
|
* 【core 】 StrUtil.insert支持负数index
|
||||||
|
* 【core 】 Calculator类支持取模运算(issue#I40DUW@Gitee)
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【core 】 修复FileUtil.normalize处理上级路径的问题(issue#I3YPEH@Gitee)
|
* 【core 】 修复FileUtil.normalize处理上级路径的问题(issue#I3YPEH@Gitee)
|
||||||
@ -18,6 +19,7 @@
|
|||||||
* 【core 】 修复FastDatePrinter歧义问题(pr#366@Gitee)
|
* 【core 】 修复FastDatePrinter歧义问题(pr#366@Gitee)
|
||||||
* 【core 】 修复DateUtil.format格式化Instant报错问题(issue#I40CY2@Gitee)
|
* 【core 】 修复DateUtil.format格式化Instant报错问题(issue#I40CY2@Gitee)
|
||||||
* 【core 】 修复StrUtil.toUnderlineCase大写问题(issue#I40CGS@Gitee)
|
* 【core 】 修复StrUtil.toUnderlineCase大写问题(issue#I40CGS@Gitee)
|
||||||
|
* 【jwt 】 修复JWT.validate报错问题(issue#I40MR2@Gitee)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ public class Calculator {
|
|||||||
* @return 是否为算术符号
|
* @return 是否为算术符号
|
||||||
*/
|
*/
|
||||||
private boolean isOperator(char c) {
|
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 优先级
|
* @return 优先级
|
||||||
*/
|
*/
|
||||||
public boolean compare(char cur, char peek) {// 如果是peek优先级高于cur,返回true,默认都是peek优先级要低
|
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 firstValue 第一个值
|
||||||
* @param secondValue 第二个值
|
* @param secondValue 第二个值
|
||||||
* @param currentOp 算数符,只支持'+'、'-'、'*'、'/'
|
* @param currentOp 算数符,只支持'+'、'-'、'*'、'/'、'%'
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
private BigDecimal calculate(String firstValue, String secondValue, char currentOp) {
|
private BigDecimal calculate(String firstValue, String secondValue, char currentOp) {
|
||||||
@ -181,6 +191,9 @@ public class Calculator {
|
|||||||
case '/':
|
case '/':
|
||||||
result = NumberUtil.div(firstValue, secondValue);
|
result = NumberUtil.div(firstValue, secondValue);
|
||||||
break;
|
break;
|
||||||
|
case '%':
|
||||||
|
result = NumberUtil.toBigDecimal(firstValue).remainder(NumberUtil.toBigDecimal(secondValue));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected value: " + currentOp);
|
throw new IllegalStateException("Unexpected value: " + currentOp);
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable {
|
|||||||
if(index < 0){
|
if(index < 0){
|
||||||
index = this.position + index;
|
index = this.position + index;
|
||||||
}
|
}
|
||||||
if ((index < 0) || (index > this.position)) {
|
if ((index < 0)) {
|
||||||
throw new StringIndexOutOfBoundsException(index);
|
throw new StringIndexOutOfBoundsException(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable {
|
|||||||
if(index < 0){
|
if(index < 0){
|
||||||
index = this.position + index;
|
index = this.position + index;
|
||||||
}
|
}
|
||||||
if ((index < 0) || (index > this.position)) {
|
if ((index < 0)) {
|
||||||
throw new StringIndexOutOfBoundsException(index);
|
throw new StringIndexOutOfBoundsException(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,7 +252,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable {
|
|||||||
if(index < 0){
|
if(index < 0){
|
||||||
index = this.position + index;
|
index = this.position + index;
|
||||||
}
|
}
|
||||||
if ((index < 0) || (index > this.position)) {
|
if ((index < 0)) {
|
||||||
throw new StringIndexOutOfBoundsException(index);
|
throw new StringIndexOutOfBoundsException(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,7 +309,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable {
|
|||||||
if(index < 0){
|
if(index < 0){
|
||||||
index = this.position + index;
|
index = this.position + index;
|
||||||
}
|
}
|
||||||
if ((index < 0) || (index > this.position)) {
|
if ((index < 0)) {
|
||||||
throw new StringIndexOutOfBoundsException(index);
|
throw new StringIndexOutOfBoundsException(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,4 +22,10 @@ public class CalculatorTest {
|
|||||||
final double conversion = Calculator.conversion("1");
|
final double conversion = Calculator.conversion("1");
|
||||||
Assert.assertEquals(1, conversion, 2);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,6 @@ public class StrBuilderTest {
|
|||||||
public void delTest2() {
|
public void delTest2() {
|
||||||
// 删除中间部分测试
|
// 删除中间部分测试
|
||||||
StrBuilder strBuilder = new StrBuilder("ABCDEFG");
|
StrBuilder strBuilder = new StrBuilder("ABCDEFG");
|
||||||
int length = strBuilder.length();
|
|
||||||
StrBuilder builder = strBuilder.del(2,6);
|
StrBuilder builder = strBuilder.del(2,6);
|
||||||
Assert.assertEquals("ABG", builder.toString());
|
Assert.assertEquals("ABG", builder.toString());
|
||||||
}
|
}
|
||||||
|
@ -352,7 +352,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
|||||||
|
|
||||||
// 校验时间字段
|
// 校验时间字段
|
||||||
try {
|
try {
|
||||||
JWTValidator.of(tokens.get(2)).validateDate(DateUtil.date(), leeway);
|
JWTValidator.of(this).validateDate(DateUtil.date(), leeway);
|
||||||
} catch (ValidateException e) {
|
} catch (ValidateException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package cn.hutool.jwt;
|
|||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.exceptions.ValidateException;
|
import cn.hutool.core.exceptions.ValidateException;
|
||||||
import cn.hutool.jwt.signers.JWTSignerUtil;
|
import cn.hutool.jwt.signers.JWTSignerUtil;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class JWTValidatorTest {
|
public class JWTValidatorTest {
|
||||||
@ -60,4 +61,12 @@ public class JWTValidatorTest {
|
|||||||
// 验证算法
|
// 验证算法
|
||||||
JWTValidator.of(token).validateAlgorithm(JWTSignerUtil.hs256("123456".getBytes()));
|
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