Skip to content

Commit 8c0d22d

Browse files
committed
Merge branch 'hotfix/Issue-26'
2 parents 8cb2623 + b66779a commit 8c0d22d

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

Controls/UploadImages.ascx.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ Namespace Ventrian.NewsArticles.Controls
581581
If (_articleID = Null.NullInteger) Then
582582
objImage.ImageGuid = ArticleGuid
583583
End If
584-
objImage.FileName = objFile.FileName
584+
objImage.FileName = CoreFileProvider.CleanFilename(objFile.FileName)
585585

586586
If (objFile.FileName.ToLower().EndsWith(".jpg")) Then
587587
objImage.ContentType = "image/jpeg"

Installs/NewsArticles.00.11.01.zip

772 KB
Binary file not shown.

Providers/FileProvider/CoreFileProvider.vb

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Namespace Ventrian.NewsArticles
1717
Dim objFile As New FileInfo
1818

1919
objFile.ArticleID = articleID
20-
objFile.FileName = objPostedFile.FileName
20+
objFile.FileName = CleanFilename(objPostedFile.FileName)
2121
objFile.SortOrder = 0
2222

2323
Dim filesList As List(Of FileInfo) = GetFiles(articleID)
@@ -129,6 +129,31 @@ Namespace Ventrian.NewsArticles
129129
End Sub
130130

131131
#End Region
132+
133+
''' <summary>
134+
''' Cleans a filename from forbidden characters on Windows Filesystems
135+
''' </summary>
136+
''' <param name="filename"></param>
137+
''' <returns></returns>
138+
public shared Function CleanFilename(ByVal filename As String) As String
139+
' stuk vanaf de laatste forward of backslash is de bestandsnaam
140+
' bestandsnaam zonder extensie moet worden beperkt tot max 200 karakters.
141+
Dim retval As String = ""
142+
Dim folderChars = "\/"
143+
144+
If filename.LastIndexOfAny(folderChars.ToCharArray()) >= 0 Then
145+
retval = filename.Substring(filename.LastIndexOfAny(folderChars.ToCharArray()) + 1)
146+
Else
147+
retval = filename
148+
End If
149+
' forbidden characters are: \/:*?"<>|
150+
Dim regex = New Regex("[:\\/\*\?""<>\|]", RegexOptions.CultureInvariant Or RegexOptions.Compiled)
151+
' Replace the matched text in the InputText using the replacement pattern
152+
retval = regex.Replace(retval, "-")
153+
154+
'If retval.Length > 200 Then retval = retval.Substring(0, 200)
155+
Return retval
156+
End Function
132157

133158
End Class
134159

ucSubmitNews.ascx.vb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,7 @@ Namespace Ventrian.NewsArticles
14561456
cmdSaveArticle.ValidationGroup = vgId
14571457
End Sub
14581458

1459+
14591460
#End Region
14601461

14611462
#Region " Event Handlers "

0 commit comments

Comments
 (0)