Commit e93c7f0e75c66121bb6c72228b2a10764b292e96

Authored by guzijian
1 parent 32268d55

fix: 修复正则校验异常问题。

Bsth-admin/src/main/java/com/ruoyi/service/ReportService.java
@@ -357,7 +357,7 @@ public class ReportService { @@ -357,7 +357,7 @@ public class ReportService {
357 return Result.ERROR(ResultCode.CODE_401, "X-TOKEN-AUTHORIZATION value error"); 357 return Result.ERROR(ResultCode.CODE_401, "X-TOKEN-AUTHORIZATION value error");
358 } 358 }
359 if (!validateDayDate) { 359 if (!validateDayDate) {
360 - return Result.ERROR(ResultCode.CODE_400, "Parameter format error"); 360 + return Result.ERROR(ResultCode.CODE_400, "Date parameter format error");
361 } 361 }
362 ReportViewRequestVo vo = new ReportViewRequestVo(); 362 ReportViewRequestVo vo = new ReportViewRequestVo();
363 vo.setDate(date); 363 vo.setDate(date);
@@ -373,13 +373,24 @@ public class ReportService { @@ -373,13 +373,24 @@ public class ReportService {
373 * yyyy-MM 格式的正则表达式 373 * yyyy-MM 格式的正则表达式
374 */ 374 */
375 public static boolean validateDayDate(String input) { 375 public static boolean validateDayDate(String input) {
376 - String regex = "(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|\"+\n" +  
377 - "\"((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|\"+\n" +  
378 - "\"((0[48]|[2468][048]|[3579][26])00))-02-29)$";  
379 -  
380 - Pattern pattern = Pattern.compile(regex);  
381 - Matcher matcher = pattern.matcher(input);  
382 -  
383 - return matcher.matches(); 376 + String datePattern1 = "\\d{4}-\\d{2}-\\d{2}";
  377 + String datePattern2 = "^((\\d{2}(([02468][048])|([13579][26]))"
  378 + + "[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|"
  379 + + "(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?"
  380 + + "((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?("
  381 + + "(((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?"
  382 + + "((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))";
  383 + if ((input != null)) {
  384 + Pattern pattern = Pattern.compile(datePattern1);
  385 + Matcher match = pattern.matcher(input);
  386 + if (match.matches()) {
  387 + pattern = Pattern.compile(datePattern2);
  388 + match = pattern.matcher(input);
  389 + return match.matches();
  390 + } else {
  391 + return false;
  392 + }
  393 + }
  394 + return false;
384 } 395 }
385 } 396 }