From 90e1f3beff74b42b16cad915c2e0be9a7615b4dd Mon Sep 17 00:00:00 2001 From: mbays Date: Fri, 1 Apr 2022 00:00:00 +0000 Subject: [PATCH] validate mark names --- Marks.hs | 7 ++++++- diohsc.hs | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Marks.hs b/Marks.hs index 729b615..8896b43 100644 --- a/Marks.hs +++ b/Marks.hs @@ -17,6 +17,7 @@ module Marks where import Control.Exception (handle) import Control.Monad (guard, msum) import Data.Bifunctor (second) +import Data.Char (isAlphaNum) import Data.Either (partitionEithers) import Data.List (isPrefixOf) import System.Directory @@ -77,10 +78,14 @@ loadMarks path = "Failed to decode uri in:" ++ show filepath) (Right . (filename,)) . readUriWithId . TS.strip . TS.decodeUtf8 <$> BS.readFile filepath +markNameValid :: String -> Bool +markNameValid = all isAlphaNum + saveMark :: FilePath -> String -> URIWithIdName -> IO () -saveMark path mark uriId = +saveMark path mark uriId | markNameValid mark = let filepath = path mark in isSubPath path filepath >>? mkdirhierto filepath >> writeFile filepath (showUriWithId uriId) +saveMark _ _ _ = pure () marksWithUri :: URI -> Marks -> [(String,URIWithIdName)] marksWithUri uri = Map.toList . Map.filter ((==uri) . uriIdUri) diff --git a/diohsc.hs b/diohsc.hs index 33a6a54..8f5d913 100644 --- a/diohsc.hs +++ b/diohsc.hs @@ -564,10 +564,11 @@ handleCommandLine marksDir = userDataDir "marks" setMark :: String -> URIWithIdName -> ClientM () - setMark mark uriId = do + setMark mark uriId | markNameValid mark = do modify $ \s -> s { clientMarks = insertMark mark uriId $ clientMarks s } unless (mark `elem` tempMarks) . liftIO . handle printIOErr $ saveMark marksDir mark uriId + setMark mark _ = printErr $ "Invalid mark name " ++ mark promptInput = if ghost then promptLine else promptLineWithHistoryFile inputHistPath where inputHistPath = userDataDir "inputHistory" -- 2.11.4.GIT