@@ -13,7 +13,7 @@ module Hledger.Web.Widget.AddForm
1313
1414import Control.Monad.State.Strict (evalStateT )
1515import Data.Bifunctor (first )
16- import Data.List (dropWhileEnd , nub , sort , unfoldr )
16+ import Data.List (dropWhileEnd , intercalate , nub , sort , unfoldr )
1717import Data.Maybe (isJust )
1818#if !(MIN_VERSION_base(4,13,0))
1919import Data.Semigroup ((<>) )
@@ -73,10 +73,6 @@ addForm j today = identifyForm "add" $ \extra -> do
7373 -- bindings used in add-form.hamlet
7474 let descriptions = sort $ nub $ tdescription <$> jtxns j
7575 journals = fst <$> jfiles j
76- listToJsonArray :: [Text ] -> Markup
77- listToJsonArray = preEscapedString . escapeJSSpecialChars . show . toJSON
78- where
79- escapeJSSpecialChars = regexReplaceCI " </script>" " <\\ /script>" -- #236
8076
8177 pure (validateTransaction dateRes descRes postRes, $ (widgetFile " add-form" ))
8278
@@ -98,6 +94,28 @@ addForm j today = identifyForm "add" $ \extra -> do
9894 , fieldEnctype = UrlEncoded
9995 }
10096
97+ -- Used in add-form.hamlet
98+ toBloodhoundJson :: [Text ] -> Markup
99+ toBloodhoundJson ts =
100+ -- This used to work, but since 1.16, it seems like something changed.
101+ -- toJSON ("a"::Text) gives String "a" instead of "a", etc.
102+ -- preEscapedString . escapeJSSpecialChars . show . toJSON
103+ preEscapedString $ concat [
104+ " [" ,
105+ intercalate " ," $ map (
106+ (" {\" value\" :" ++ ).
107+ (++ " }" ).
108+ escapeJSSpecialChars .
109+ drop 7 . -- "String "
110+ show .
111+ toJSON
112+ ) ts,
113+ " ]"
114+ ]
115+ where
116+ -- avoid https://github.com/simonmichael/hledger/issues/236
117+ escapeJSSpecialChars = regexReplaceCI " </script>" " <\\ /script>"
118+
101119validateTransaction ::
102120 FormResult Day
103121 -> FormResult Text
0 commit comments