summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorstuebinm2022-03-19 16:50:57 +0100
committerstuebinm2022-03-19 20:00:54 +0100
commit25111b467c91e411f1c7a4281c2eee5671db7406 (patch)
tree96fdc517c1a5f0097df525fb5fc713bd4d84ac29 /lib
parent8a0a463f1e45c990fb417c3d08f9f8e7e5643212 (diff)
linter: allow unrestricted domain scopes
Diffstat (limited to 'lib')
-rw-r--r--lib/Uris.hs15
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/Uris.hs b/lib/Uris.hs
index a8c7068..596c272 100644
--- a/lib/Uris.hs
+++ b/lib/Uris.hs
@@ -23,6 +23,7 @@ data Substitution =
Prefixed { prefix :: Text, blocked :: [Text], allowed :: [Text], scope :: [String] }
| DomainSubstitution { substs :: Map Text Text, scope :: [String] }
| Allowed { scope :: [String], allowed :: [Text] }
+ | Unrestricted { scope :: [String] }
deriving (Generic, Show)
@@ -32,7 +33,7 @@ instance FromJSON Substitution where
, rejectUnknownFields = True
}
-type SchemaSet = [(Text, Substitution)]
+type SchemaSet = Map Text Substitution
extractDomain :: Text -> Maybe Text
@@ -78,20 +79,17 @@ applySubsts s substs uri = do
$ Left VarsDisallowed
parts@(schema, _, _) <- note NotALink $ parseUri uri
- let rules = filter ((==) schema . fst) substs
+ let rule = M.lookup schema substs
- case nonEmpty (map (applySubst parts . snd) rules) of
+ case map (applySubst parts) rule of
Nothing -> Left (SchemaDoesNotExist schema)
- Just results -> case rights (toList results) of
- suc:_ -> Right suc
- _ -> minimum results
-
+ Just result -> result
where
note = maybeToRight
applySubst (schema, domain, rest) rule = do
unless (symbolVal s `elem` scope rule)
$ Left (WrongScope schema
- (fmap fst . filter (elem (symbolVal s) . scope . snd) $ substs))
+ (map fst . filter (elem (symbolVal s) . scope . snd) $ toPairs substs))
case rule of
DomainSubstitution table _ -> do
prefix <- note (DomainDoesNotExist (schema <> toText "://" <> domain))
@@ -105,3 +103,4 @@ applySubsts s substs uri = do
|| toText "streamproxy.rc3.world" `T.isSuffixOf` domain
then Right uri
else Left (DomainIsBlocked domains)
+ Unrestricted _ -> Right uri