Skip to content

Commit

Permalink
Merge tag 'Issue-26' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
skamphuis committed Jan 25, 2019
2 parents 8cb2623 + 8c0d22d commit 25aad5b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Controls/UploadImages.ascx.vb
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ Namespace Ventrian.NewsArticles.Controls
If (_articleID = Null.NullInteger) Then
objImage.ImageGuid = ArticleGuid
End If
objImage.FileName = objFile.FileName
objImage.FileName = CoreFileProvider.CleanFilename(objFile.FileName)

If (objFile.FileName.ToLower().EndsWith(".jpg")) Then
objImage.ContentType = "image/jpeg"
Expand Down
Binary file added Installs/NewsArticles.00.11.01.zip
Binary file not shown.
27 changes: 26 additions & 1 deletion Providers/FileProvider/CoreFileProvider.vb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Namespace Ventrian.NewsArticles
Dim objFile As New FileInfo

objFile.ArticleID = articleID
objFile.FileName = objPostedFile.FileName
objFile.FileName = CleanFilename(objPostedFile.FileName)
objFile.SortOrder = 0

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

#End Region

''' <summary>
''' Cleans a filename from forbidden characters on Windows Filesystems
''' </summary>
''' <param name="filename"></param>
''' <returns></returns>
public shared Function CleanFilename(ByVal filename As String) As String
' stuk vanaf de laatste forward of backslash is de bestandsnaam
' bestandsnaam zonder extensie moet worden beperkt tot max 200 karakters.
Dim retval As String = ""
Dim folderChars = "\/"

If filename.LastIndexOfAny(folderChars.ToCharArray()) >= 0 Then
retval = filename.Substring(filename.LastIndexOfAny(folderChars.ToCharArray()) + 1)
Else
retval = filename
End If
' forbidden characters are: \/:*?"<>|
Dim regex = New Regex("[:\\/\*\?""<>\|]", RegexOptions.CultureInvariant Or RegexOptions.Compiled)
' Replace the matched text in the InputText using the replacement pattern
retval = regex.Replace(retval, "-")

'If retval.Length > 200 Then retval = retval.Substring(0, 200)
Return retval
End Function

End Class

Expand Down
1 change: 1 addition & 0 deletions ucSubmitNews.ascx.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,7 @@ Namespace Ventrian.NewsArticles
cmdSaveArticle.ValidationGroup = vgId
End Sub


#End Region

#Region " Event Handlers "
Expand Down

0 comments on commit 25aad5b

Please sign in to comment.