Skip to content

Commit

Permalink
Make relativeTo and nonStrictRelative not wrap result in Maybe
Browse files Browse the repository at this point in the history
The functions were always returning Just. Also, according to the RFC the
algorithm is not guaranteed to return an absolute URL.

Fixes #50.
  • Loading branch information
tibbe committed Sep 10, 2012
1 parent 110a7da commit 4a3fdef
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Network/URI.hs
Expand Up @@ -989,7 +989,7 @@ unEscapeString (c:s) = c : unEscapeString s
-- Algorithm from RFC3986 [3], section 5.2.2
--

nonStrictRelativeTo :: URI -> URI -> Maybe URI
nonStrictRelativeTo :: URI -> URI -> URI
nonStrictRelativeTo ref base = relativeTo ref' base
where
ref' = if uriScheme ref == uriScheme base
Expand All @@ -999,9 +999,11 @@ nonStrictRelativeTo ref base = relativeTo ref' base
isDefined :: ( MonadPlus m, Eq (m a) ) => m a -> Bool
isDefined a = a /= mzero

-- |Compute an absolute 'URI' for a supplied URI
-- relative to a given base.
relativeTo :: URI -> URI -> Maybe URI
-- | Returns a new 'URI' which represents the value of the first 'URI'
-- interpreted as relative to the second 'URI'.
--
-- Algorithm from RFC3986 [3], section 5.2
relativeTo :: URI -> URI -> URI
relativeTo ref base
| isDefined ( uriScheme ref ) =
just_segments ref
Expand Down Expand Up @@ -1034,7 +1036,7 @@ relativeTo ref base
}
where
just_segments u =
Just $ u { uriPath = removeDotSegments (uriPath u) }
u { uriPath = removeDotSegments (uriPath u) }
mergePaths b r
| isDefined (uriAuthority b) && null pb = '/':pr
| otherwise = dropLast pb ++ pr
Expand Down

0 comments on commit 4a3fdef

Please sign in to comment.