Skip to content

Commit

Permalink
cli: Commands.Balance.registerQueryUrl: correctly escape URL using mo…
Browse files Browse the repository at this point in the history
…dern-uri package
  • Loading branch information
thielema authored and simonmichael committed Sep 29, 2024
1 parent 67c8a6e commit 35f2709
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions hledger/Hledger/Cli/Commands/Balance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ Currently, empty cells show 0.
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE QuasiQuotes #-}

module Hledger.Cli.Commands.Balance (
-- ** balance command
Expand Down Expand Up @@ -283,6 +284,8 @@ import Data.Time (addDays, fromGregorian)
import System.Console.CmdArgs.Explicit as C (flagNone, flagReq, flagOpt)
import Lucid as L hiding (value_)
import Safe (headMay, maximumMay)
import qualified Text.URI as Uri
import qualified Text.URI.QQ as UriQQ
import Text.Tabular.AsciiWide
(Header(..), Align(..), Properties(..), Cell(..), Table(..), TableOpts(..),
cellWidth, concatTables, renderColumns, renderRowB, renderTableByRowsB, textCell)
Expand Down Expand Up @@ -586,8 +589,14 @@ headerCell text =

registerQueryUrl :: [Text] -> Text
registerQueryUrl query =
"register?q=" <>
T.intercalate "+" (map quoteIfSpaced $ filter (not . T.null) query)
Uri.render $
[UriQQ.uri|register|] {
Uri.uriQuery =
[Uri.QueryParam [UriQQ.queryKey|q|] $
fromMaybe (error "register URI query construction failed") $
Uri.mkQueryValue $ T.unwords $
map quoteIfSpaced $ filter (not . T.null) query]
}

-- cf. Web.Widget.Common
removeDates :: [Text] -> [Text]
Expand Down
1 change: 1 addition & 0 deletions hledger/hledger.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ library
, math-functions >=0.3.3.0
, megaparsec >=7.0.0 && <9.7
, microlens >=0.4
, modern-uri >=0.3
, mtl >=2.2.1
, process
, regex-tdfa
Expand Down
1 change: 1 addition & 0 deletions hledger/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ library:
- Diff >=0.2
- hashable >=1.2.4
- lucid
- modern-uri >=0.3

executables:
hledger:
Expand Down

0 comments on commit 35f2709

Please sign in to comment.