diff --git a/src/Servant/PY/Internal.hs b/src/Servant/PY/Internal.hs index eb6eecb..636c3ba 100644 --- a/src/Servant/PY/Internal.hs +++ b/src/Servant/PY/Internal.hs @@ -262,15 +262,14 @@ makePyUrl opts (TypedPythonRequest req) offset = makePyUrl' opts req offset makePyUrl opts (UnTypedPythonRequest req) offset = makePyUrl' opts req offset makePyUrl' :: forall f. CommonGeneratorOptions -> Req f -> Text -> Text -makePyUrl' opts req offset = "\"" <> url <> "\"" +makePyUrl' opts req offset = "\"" <> url <> "\"" <> withFormattedCaptures offset pathParts where url = urlPrefix opts <> "/" <> getSegments pathParts - <> withFormattedCaptures offset pathParts pathParts = req ^.. reqUrl.path.traverse getSegments :: forall f. [Segment f] -> Text getSegments segments = if null segments then "" - else T.intercalate "/" (map segmentToStr segments) <> "\"" + else T.intercalate "/" (map segmentToStr segments) withFormattedCaptures :: Text -> [Segment f] -> Text withFormattedCaptures offset segments = formattedCaptures (capturesToFormatArgs segments) diff --git a/test/Servant/PY/InternalSpec.hs b/test/Servant/PY/InternalSpec.hs index 20cc19c..6da4a0b 100644 --- a/test/Servant/PY/InternalSpec.hs +++ b/test/Servant/PY/InternalSpec.hs @@ -126,10 +126,10 @@ internalSpec = describe "Internal" $ do it "should build a formatted val that ends with parens" $ property $ \s -> T.isSuffixOf (T.pack s <> "))") $ formatBuilder $ T.pack s - -- it "should build urls properly with / separator" $ do - -- let pyUrl = makePyUrl customOptions req " " - -- pyUrl `shouldBe` "\"urlForRequesting:9000/login-with-path-var-and-header/{id}/{Name}/{hungrig}\"" - -- <> withFormattedCaptures " " pathParts + it "should build urls properly with / separator" $ do + let pyUrl = makePyUrl customOptions (UnTypedPythonRequest req) " " + pyUrl `shouldBe` "\"urlForRequesting:9000/login-with-path-var-and-header/{id}/{Name}/{hungrig}\"" + <> withFormattedCaptures " " pathParts it "should do segment-to-str as a plain string for Static" $ segmentToStr (head pathParts) == "login-with-path-var-and-header"