ndmitchell / hoogle

Haskell API search engine
http://hoogle.haskell.org/
Other
738 stars 134 forks source link

Links to _ are wrong #103

Closed ndmitchell closed 9 years ago

ndmitchell commented 9 years ago

Search for catch with http://hoogle.haskell.org/?hoogle=catch

Observe the first result goes to https://hackage.haskell.org/package/extra-1.1/docs/Control-Exception-Extra.html#v:catch-95-, but it should go to https://hackage.haskell.org/package/extra-1.1/docs/Control-Exception-Extra.html#v:catch_ .

hdgarrood commented 9 years ago

Looks like this is the culprit: https://github.com/ndmitchell/hoogle/blob/master/src/Input/Hoogle.hs#L108

I'm going to try to find the code that performs that encoding, which is presumably in Haddock somewhere, to make sure we handle all the cases correctly.

ndmitchell commented 9 years ago

Yep, agreed. It doesn't seem to fail too much, so I suspect _ might be the only character mishandled - but checking Haddock is of course the best way to be sure.

hdgarrood commented 9 years ago

I'm pretty sure this is it:

-- | Takes an arbitrary string and makes it a valid anchor ID. The mapping is
-- identity preserving.
makeAnchorId :: String -> String
makeAnchorId [] = []
makeAnchorId (f:r) = escape isAlpha f ++ concatMap (escape isLegal) r
  where
    escape p c | p c = [c]
               | otherwise = '-' : show (ord c) ++ "-"
    isLegal ':' = True
    isLegal '_' = True
    isLegal '.' = True
    isLegal c = isAscii c && isAlphaNum c

Looks like it gets called with the "t:" or "v:" prefix already there (given this, for example, and also from looking at the haddock code) so I think we just need to take isLegal

hdgarrood commented 9 years ago

In haddock-api:Haddock.Utils

ndmitchell commented 9 years ago

Pull merged, all looks good - thanks!