Skip to content

Commit

Permalink
🎨 Improve ID format validation siyuan-note/siyuan#12824
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Oct 18, 2024
1 parent 3a8937b commit 14085ca
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions ast/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"bytes"
"math/rand"
"sort"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -182,14 +183,35 @@ func IsNodeIDPattern(str string) bool {
return false
}

// 检查时间部分的范围是否正确,比如年份为 0000-9999,月份为 01-12,日期为 01-31,小时为 00-23,分钟为 00-59,秒为 00-59
// 检查时间部分的范围是否正确,年份为 0000-9999,月份为 01-12,日期为 01-31,小时为 00-23,分钟为 00-59,秒为 00-59
year, month, day, hour, minute, second := idPart[:4], idPart[4:6], idPart[6:8], idPart[8:10], idPart[10:12], idPart[12:14]
if "0000" > year || "9999" < year ||
"01" > month || "12" < month ||
"01" > day || "31" < day ||
"00" > hour || "23" < hour ||
"00" > minute || "59" < minute ||
"00" > second || "59" < second {
yearInt, err := strconv.Atoi(year)
if err != nil || yearInt < 0 || yearInt > 9999 {
return false
}

monthInt, err := strconv.Atoi(month)
if err != nil || monthInt < 1 || monthInt > 12 {
return false
}

dayInt, err := strconv.Atoi(day)
if err != nil || dayInt < 1 || dayInt > 31 {
return false
}

hourInt, err := strconv.Atoi(hour)
if err != nil || hourInt < 0 || hourInt > 23 {
return false
}

minuteInt, err := strconv.Atoi(minute)
if err != nil || minuteInt < 0 || minuteInt > 59 {
return false
}

secondInt, err := strconv.Atoi(second)
if err != nil || secondInt < 0 || secondInt > 59 {
return false
}

Expand Down

0 comments on commit 14085ca

Please sign in to comment.