@@ -13,7 +13,7 @@ import qualified Data.ByteString.Lazy as L
1313import qualified Data.Map as Map
1414import Happstack.Server ( Request (.. ), Method (.. ), Response (.. ), ServerPart , Headers , RqBody (Body ), HttpVersion (.. )
1515 , ToMessage (.. ), HeaderPair (.. ), ok , dir , simpleHTTP'' , composeFilter , noContentLength , matchMethod )
16- import Happstack.Server.FileServe.BuildingBlocks (sendFileResponse )
16+ import Happstack.Server.FileServe.BuildingBlocks (sendFileResponse , combineSafe )
1717import Happstack.Server.Cookie
1818import Happstack.Server.Internal.Compression
1919import Happstack.Server.Internal.Cookie
@@ -34,6 +34,7 @@ allTests =
3434 , matchMethodTest
3535 , cookieHeaderOrderTest
3636 , pContentDispositionFilename
37+ , combineSafeTest
3738 ]
3839
3940cookieParserTest :: Test
@@ -247,3 +248,16 @@ pContentDispositionFilename =
247248 do let doesNotWorkWithOldParserButWithNew = " form-data; filename=\" file.pdf\" ; name=\" file\" " :: String
248249 c <- parseContentDisposition doesNotWorkWithOldParserButWithNew
249250 assertEqual " parseContentDisposition" c (ContentDisposition " form-data" [(" filename" ," file.pdf" ),(" name" ," file" )])
251+
252+ -- | Make sure 'combineSafe' works correctly
253+ combineSafeTest :: Test
254+ combineSafeTest =
255+ " combineSafeTest" ~:
256+ do r1 <- combineSafe " /var/uploads/" " etc/passwd"
257+ r2 <- combineSafe " /var/uploads/" " /etc/passwd"
258+ r3 <- combineSafe " /var/uploads/" " ../../etc/passwd"
259+ r4 <- combineSafe " /var/uploads/" " ../uploads/home/../etc/passwd"
260+ r1 @?= Just " /var/uploads/etc/passwd"
261+ r2 @?= Nothing
262+ r3 @?= Nothing
263+ r4 @?= Just " /var/uploads/etc/passwd"
0 commit comments