From 78f6c6c7eb9d775132b1411f6f02dc7cc3718515 Mon Sep 17 00:00:00 2001 From: vi Date: Thu, 5 Nov 2015 20:55:09 +0800 Subject: [PATCH] Data.Text.{head,last} aren't total. --- .../src/Data/HTTPSEverywhere/Rules/Internal/Parser.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/https-everywhere-rules/src/Data/HTTPSEverywhere/Rules/Internal/Parser.hs b/https-everywhere-rules/src/Data/HTTPSEverywhere/Rules/Internal/Parser.hs index 7381d1d..225a3ce 100644 --- a/https-everywhere-rules/src/Data/HTTPSEverywhere/Rules/Internal/Parser.hs +++ b/https-everywhere-rules/src/Data/HTTPSEverywhere/Rules/Internal/Parser.hs @@ -9,7 +9,7 @@ module Data.HTTPSEverywhere.Rules.Internal.Parser ( #endif ) where -import Prelude hiding (head, last, tail, init) +import Prelude hiding (head, last, tail, init, length) import Control.Applicative ((<$>)) import Control.Lens (toListOf, only, to, (^..), (^.), (&), (<&>), _Just) import Control.Monad (join) @@ -17,7 +17,7 @@ import Data.Functor.Infix ((<$$>)) import Data.Maybe (catMaybes, fromJust, fromMaybe) import Data.String.Conversions (cs) import qualified Data.Text as Strict (Text) -import Data.Text (append, head, last, tail, init, replace) +import Data.Text (append, head, last, tail, init, replace, length) import qualified Data.Text.Lazy as Lazy (Text) import Network.HTTP.Client (Cookie(..)) import Network.URI (URI(uriAuthority), URIAuth(uriRegName), parseURI) @@ -40,6 +40,7 @@ parseRuleSet xml = xml ^. attr "name" <&> \ruleSetName -> do parseTarget :: Strict.Text -> Target parseTarget = Target . checkRegName . fromJust . match . fromWildcard . replace "." "\\." where fromWildcard str + | length str == 0 = str | head str == '*' = flip append ".*" $ tail str | last str == '*' = append ".*" $ init str | otherwise = str