Only allow predefined extensions
This commit is contained in:
parent
4e7e3ff91f
commit
2f5bec7bb6
@ -84,6 +84,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Config.vb" />
|
||||
<Compile Include="Modules\BaseModule.vb" />
|
||||
<Compile Include="Modules\Constants.vb" />
|
||||
<Compile Include="Modules\ISync.vb" />
|
||||
<Compile Include="Modules\Sharepoint\Constants.vb" />
|
||||
<Compile Include="Modules\Sharepoint\Entities\SharepointDocument.vb" />
|
||||
|
||||
26
Connectors.Common/Modules/Constants.vb
Normal file
26
Connectors.Common/Modules/Constants.vb
Normal file
@ -0,0 +1,26 @@
|
||||
Public Class Constants
|
||||
Public Shared Property AllowedExtensions As New List(Of String) From {
|
||||
"pdf",
|
||||
"txt",
|
||||
"pptx",
|
||||
"docx",
|
||||
"xlsx",
|
||||
"ppt",
|
||||
"doc",
|
||||
"xls",
|
||||
"msg",
|
||||
"csv",
|
||||
"dxf",
|
||||
"dwg",
|
||||
"jpg",
|
||||
"jpeg",
|
||||
"png",
|
||||
"zip",
|
||||
"7z",
|
||||
"mp4",
|
||||
"log",
|
||||
"jfif",
|
||||
"bmp",
|
||||
"eml"
|
||||
}
|
||||
End Class
|
||||
@ -1,5 +1,4 @@
|
||||
Imports System.IO
|
||||
Imports DigitalData.Modules.Base
|
||||
|
||||
Namespace slt.Entities
|
||||
Public Class sltDocument
|
||||
@ -25,13 +24,33 @@ Namespace slt.Entities
|
||||
End Function
|
||||
|
||||
Private Function GetExtension() As String
|
||||
If Path.HasExtension(DocOriginalFilename) Then
|
||||
Return Path.GetExtension(DocOriginalFilename)
|
||||
ElseIf Path.HasExtension(Name) Then
|
||||
Return Path.GetExtension(Name)
|
||||
Dim oExtensionFromName = GetAllowedExtension(Name)
|
||||
If oExtensionFromName IsNot Nothing Then
|
||||
Return oExtensionFromName
|
||||
End If
|
||||
|
||||
Dim oExtensionFromOriginalName = GetAllowedExtension(DocOriginalFilename)
|
||||
If oExtensionFromOriginalName IsNot Nothing Then
|
||||
Return oExtensionFromOriginalName
|
||||
End If
|
||||
|
||||
Return Nothing
|
||||
End Function
|
||||
|
||||
Private Function GetAllowedExtension(pFilename As String) As String
|
||||
If Path.HasExtension(pFilename) Then
|
||||
Dim oExtension = Path.GetExtension(pFilename)
|
||||
Dim oExtensionWithoutDot = oExtension.Substring(1).ToLower()
|
||||
|
||||
If Common.Constants.AllowedExtensions.Contains(oExtensionWithoutDot) Then
|
||||
Return oExtension
|
||||
Else
|
||||
Return Nothing
|
||||
End If
|
||||
Else
|
||||
Return Nothing
|
||||
End If
|
||||
End Function
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
@ -22,6 +22,12 @@ Namespace Connectors.Test.slt
|
||||
.Name = "Gutschrift-[TITEL].pdf"
|
||||
}
|
||||
|
||||
Public oDocument4 As New sltDocument With {
|
||||
.ExtDocId = "DOCID",
|
||||
.DocOriginalFilename = "TWZ Einbau - Pilgerweg 8 vom 20.07.2022.jpg",
|
||||
.Name = "TWZ Einbau - Pilgerweg 8 vom 20.07.2022"
|
||||
}
|
||||
|
||||
<TestMethod>
|
||||
Sub GetExtensionTest1()
|
||||
Assert.AreEqual("DOCID.dwg", oDocument1.GetUniqueFilename())
|
||||
@ -29,7 +35,7 @@ Namespace Connectors.Test.slt
|
||||
|
||||
<TestMethod>
|
||||
Sub GetExtensionTest2()
|
||||
Assert.AreEqual("", oDocument2.GetUniqueFilename())
|
||||
Assert.AreEqual(Nothing, oDocument2.GetUniqueFilename())
|
||||
End Sub
|
||||
|
||||
<TestMethod>
|
||||
@ -37,6 +43,11 @@ Namespace Connectors.Test.slt
|
||||
Assert.AreEqual("DOCID.pdf", oDocument3.GetUniqueFilename())
|
||||
End Sub
|
||||
|
||||
<TestMethod>
|
||||
Sub GetExtensionTest4()
|
||||
Assert.AreEqual("DOCID.jpg", oDocument4.GetUniqueFilename())
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user