673c8ec88ea0fa0f83dbe81669f8dcc3d64cc674
[git-annex.git] /
1 [[!comment format=mdwn
2  username="joey"
3  subject="""comment 1"""
4  date="2021-11-15T16:04:31Z"
5  content="""
6 To reproduce this, I had to set LANG=C. Using a unicode locale avoids
7 the problem.
8
9 The `.met` file indicates it's a problem with encoding of metadata
10 that is being imported from the feed, and so it must be the
11 itemid that is causing the problem.
12
13         <item>
14                 ...
15                 <guid>http://www.manager-tools.com/2014/01/choosing-a-company-work-chapter-7-–-questions/</guid>
16         </item>
17
18 A file with the feed edited down to just that item is enough to reproduce it.
19 Notice the unicode in the guid "chapter-7-–-questions".
20 That ENDASH character is causing the crash.
21
22 Also I noticed that the next time it runs, it skips the item, since it got
23 far enough to add the file for it and record the url before the metadata itemid
24 write crashed it. Explains why it's failing on different items in different runs.
25
26 While this looks like one of the old Handle output encoding problems, it is not,
27 because a) the itemid is written as a ByteString so encoding does not matter,
28 b) those were fixed comprehensively by forcing all handles to use filesystem
29 enconding, and c) just printing out the length of the itemid also causes a crash:
30
31         +                 liftIO $ print (L.length (journalableByteString content))
32
33         git-annex: recoverEncode: invalid argument (invalid character)
34
35 Looking at what the feed library parses:
36         
37         LANG=C ghci Utility/FileSystemEncoding.hs
38         ghci> Just f <- Text.Feed.Import.parseFeedFromFile "career_tools_podcasts.xml"
39         ghci> Just (_, x) = Text.Feed.Query.getItemId (Text.Feed.Query.feedItems f !! 0)
40         ghci> x
41         "http://www.manager-tools.com/2014/01/choosing-a-company-work-chapter-7-\8211-questions/"
42         ghci> encodeBS (Data.Text.unpack x)
43         "*** Exception: recoverEncode: invalid argument (invalid character)
44
45 So the problem is that Text parses the feed as unicode, leading to this
46 non-ascii Char that is not encoded using the filesystem encoding
47 (which would encode it as "\56546\56448\56467"). 
48 And `encodeBS "\8211"` crashes in LANG=C.
49
50 Which is a reversion of sorts; before [[!commit fa62c98910]] encodeBS did
51 not crash. Although it also didn't round-trip this value properly,
52 producing "M" for it. Since this only affects strings that are not input in
53 the filesystem encoding, I think the new encodeBS is still ok to use
54 generally; I'm not going to revert that commit.
55
56 Instead, Text values originating from Feed need to be converted to
57 String in some other way, producing a value encoded
58 using the filesystem encoding. encodeUtf8 looks like it will
59 do the right thing in this case.
60 """]]