When clicking on an account (on the left hand column) that contains an apostrophe like "Mimi's Cafe", the result that appears is always blank with a flat graph. This applies to all sub-accounts too.
Other accounts without apostrophe like "Bella Italia" doesn't have this problem.
Thanks!
Good catch! The fix might include adding a call to quoteIfNeeded in the searchform function. The bug happens only with account names containing both a space and an apostrophe (single quote). Are you a haskeller ?
Correction, I think the problem is in Common.hs (hledger-web):
accountQuery :: AccountName -> String
accountQuery a = "inacct:" ++ T.unpack (quoteIfSpaced a) -- (accountNameToAccountRegex a)
accountOnlyQuery :: AccountName -> String
accountOnlyQuery a = "inacctonly:" ++ T.unpack (quoteIfSpaced a ) -- (accountNameToAccountRegex a)
and Text.hs (hledger-lib):
-- | Wrap a string in double quotes, and \-prefix any embedded single
-- quotes, if it contains whitespace and is not already single- or
-- double-quoted.
quoteIfSpaced :: T.Text -> T.Text
quoteIfSpaced s | isSingleQuoted s || isDoubleQuoted s = s
| not $ any (`elem` (T.unpack s)) whitespacechars = s
| otherwise = "'"<>escapeSingleQuotes s<>"'"
This is a nice starter bug for anyone wanting to get started on hledger-web hacking. Steps might include:
make ghci-web:main -f examples/sample.journalExpenses:Mimi's CafeSorry, I don't speak Haskel. (Sad...) But I did find a temporary solution! I had to replace the apostrophes surrounding the account name with quotation marks "...", and then it'll work.
Example:
inacct:'Expenses:Mimi's Cafe' - fail
inacct:"Expenses:Mimi's Cafe" - works!
Are you proud of me? Huh? Are ya?
Just kidding! (I like to think programmers have a sense of humor too)
+1 creative interim solution ! :)
I'll take a look at this one.
Not a haskeller so am unfamiliar with how best modify those mentioned functions. I did confirm that an account with a single quote but no spaces behaves properly, e.g. mimi'snospace. Additionally the network request from hledger web properly encodes the single quote as %27.
It seems that isSingleQuoted should do a more comprehensive test on the account name? Or maybe the account name should have spaces stripped before invoking isSingleQuoted?
Hi Simon, I am trying to get into hledger-web with this one. Is there any reason that the documentation of quoteIfSpaced says "Wrap a string in double quotes" but the function actually wraps the string in single quotes?
Hi ptek, thanks! You're quite right, that's a mistake. Hledger.Utils.Text is a rough partial port of Hledger.Utils.String and it looks like I got confused.
Replying here re #649: I'm not sure that is right. Shouldn't it be "\""<>escapeDoubleQuotes s<>"\"" ?
The semantics of these helpers seem quite confusing, they are perhaps in need of additional clarification and some tests. Eg:
why are we using quoteIfSpaced (handles whitespace) and not quoteIfNeeded (handles whitespace and single/double quote chars) as in String.hs ?
should single quote chars be legal in account names ? If not, do we do enough validation/warning when they are used ? If yes, do we fully support that ?
same questions for double quotes
is escapeDoubleQuotes (String and Text versions) doing anything ? I don't think so
PS I tested with the following journal. hledger-web 1.5 shows the correct register screen for 5/9 txns, the #649 patch works for 7/9 txns (it fails on 2 and 4):
2018/1/1
(1:mimi's cafe) 1
2018/1/2
(2:expenses:"alex" cafe) 1
2018/1/3
(3:expenses:le'shan's cafe) 1
2018/1/4
(4:expenses:"be'any's" cafe) 1
2018/1/5
(5:a'a) 1
2018/1/6
(6:b'b'b) 1
2018/1/7
(7:c'c'c'c) 1
2018/1/8
(8:d') 1
2018/1/9
(9:a' a) 1
Ping.. would anyone like to push this to completion ?
Would you like all 9 of 9 cases in the above comment covered?
I could give it a try
@ptek that would be nice, but even better if you could investigate the points I raised in the previous comment.
Ok, I hope I have enough insight into hledger for that. Will do my best
Thanks for the help! If you'd like to look at it together, ping me on #hledger.
Most helpful comment
Ok, I hope I have enough insight into hledger for that. Will do my best