refactor: 使用正则表达式检测 NTFS 8.3 文件名

This commit is contained in:
SALTWOOD
2024-08-16 11:38:09 +08:00
parent 3af99aca0a
commit 2427fb7619
2 changed files with 16 additions and 6 deletions
@@ -1724,6 +1724,16 @@ RetryDir:
Public Function RegexReplaceEach(Input As String, Replacement As MatchEvaluator, Regex As String, Optional options As RegexOptions = RegularExpressions.RegexOptions.None) As String
Return RegularExpressions.Regex.Replace(Input, Regex, Replacement, options)
End Function
''' <summary>
''' 检查传入字符串会不会引发 Issue #4505
''' </summary>
Public Function Ntfs83NameCheck(name As String) As Boolean
Dim regex As New Regex("(.*)~(\d*)")
Dim namePart As Byte() = Encoding.UTF8.GetBytes(regex.Match(name).Groups(1).Value)
Dim numPart As Integer = regex.Match(name).Groups(2).Value.Length
Return namePart.Length >= 6 AndAlso numPart = 1
End Function
#End Region