diff --git a/hledger-lib/Hledger/Data/AccountName.hs b/hledger-lib/Hledger/Data/AccountName.hs index d773905d8..ce137e868 100644 --- a/hledger-lib/Hledger/Data/AccountName.hs +++ b/hledger-lib/Hledger/Data/AccountName.hs @@ -39,14 +39,14 @@ module Hledger.Data.AccountName ( ) where -import Data.List import Data.List.Extra (nubSort) +import qualified Data.List.NonEmpty as NE #if !(MIN_VERSION_base(4,11,0)) -import Data.Monoid +import Data.Semigroup ((<>)) #endif import Data.Text (Text) import qualified Data.Text as T -import Data.Tree +import Data.Tree (Tree(..)) import Hledger.Data.Types import Hledger.Utils @@ -115,7 +115,7 @@ expandAccountNames as = nubSort $ concatMap expandAccountName as -- | "a:b:c" -> ["a","a:b","a:b:c"] expandAccountName :: AccountName -> [AccountName] -expandAccountName = map accountNameFromComponents . tail . inits . accountNameComponents +expandAccountName = map accountNameFromComponents . NE.tail . NE.inits . accountNameComponents -- | ["a:b:c","d:e"] -> ["a","d"] topAccountNames :: [AccountName] -> [AccountName] @@ -209,8 +209,10 @@ clipOrEllipsifyAccountName n = clipAccountName n -- >>> putStr $ escapeName "First?!#$*?$(*) !@^#*? %)*!@#" -- First\?!#\$\*\?\$\(\*\) !@\^#\*\? %\)\*!@# escapeName :: AccountName -> String -escapeName = replaceAllBy (toRegex' "[[?+|()*\\\\^$]") ("\\" <>) -- PARTIAL: should not happen - . T.unpack +escapeName = T.unpack . T.concatMap escapeChar + where + escapeChar c = if c `elem` escapedChars then T.snoc "\\" c else T.singleton c + escapedChars = ['[', '?', '+', '|', '(', ')', '*', '$', '^', '\\'] -- | Convert an account name to a regular expression matching it and its subaccounts. accountNameToAccountRegex :: AccountName -> Regexp diff --git a/hledger-web/Hledger/Web/Widget/AddForm.hs b/hledger-web/Hledger/Web/Widget/AddForm.hs index e47644118..bc9138c08 100644 --- a/hledger-web/Hledger/Web/Widget/AddForm.hs +++ b/hledger-web/Hledger/Web/Widget/AddForm.hs @@ -106,16 +106,13 @@ addForm j today = identifyForm "add" $ \extra -> do intercalate "," $ map ( ("{\"value\":" ++). (++"}"). - escapeJSSpecialChars . - drop 7 . -- "String " show . - toJSON + -- avoid https://github.com/simonmichael/hledger/issues/236 + T.replace "" "<\\/script>" ) ts, "]" ] where - -- avoid https://github.com/simonmichael/hledger/issues/236 - escapeJSSpecialChars = regexReplace (toRegexCI' "") "<\\/script>" validateTransaction :: FormResult Day diff --git a/hledger-web/Hledger/Web/Widget/Common.hs b/hledger-web/Hledger/Web/Widget/Common.hs index 908c6e26e..4b75d3c36 100644 --- a/hledger-web/Hledger/Web/Widget/Common.hs +++ b/hledger-web/Hledger/Web/Widget/Common.hs @@ -72,7 +72,7 @@ writeJournalTextIfValidAndChanged f t = do -- Ensure unix line endings, since both readJournal (cf -- formatdirectivep, #1194) writeFileWithBackupIfChanged require them. -- XXX klunky. Any equivalent of "hSetNewlineMode h universalNewlineMode" for form posts ? - let t' = T.pack $ regexReplace (toRegex' "\r") "" $ T.unpack t + let t' = T.replace "\r" "" t liftIO (readJournal def (Just f) t') >>= \case Left e -> return (Left e) Right _ -> do