@@ -24,6 +24,11 @@ module Data.Swagger.Internal.AesonUtils (
24 saoPrefix,
24 saoPrefix,
25 saoAdditionalPairs,
25 saoAdditionalPairs,
26 saoSubObject,
26 saoSubObject,
27+ -- * Percent encoding
29import Prelude ()
34import Prelude ()
@@ -330,3 +335,55 @@ sopSwaggerGenericToEncoding'' (SwaggerAesonOptions prefix _ sub) = go
330 where (x, y) = span isUpper s
335 where (x, y) = span isUpper s
339+percentEncodeS :: String -> String
340+percentEncodeS "" = ""
341+percentEncodeS ('!' : s) = "%21" <> percentEncodeS s
342+percentEncodeS ('#' : s) = "%23" <> percentEncodeS s
343+percentEncodeS ('$' : s) = "%24" <> percentEncodeS s
344+percentEncodeS ('%' : s) = "%25" <> percentEncodeS s
345+percentEncodeS ('&' : s) = "%26" <> percentEncodeS s
346+percentEncodeS ('\'' : s) = "%27" <> percentEncodeS s
347+percentEncodeS ('(' : s) = "%28" <> percentEncodeS s
348+percentEncodeS (')' : s) = "%29" <> percentEncodeS s
349+percentEncodeS ('*' : s) = "%2A" <> percentEncodeS s
350+percentEncodeS ('+' : s) = "%2B" <> percentEncodeS s
351+percentEncodeS (',' : s) = "%2C" <> percentEncodeS s
352+percentEncodeS ('/' : s) = "%2F" <> percentEncodeS s
353+percentEncodeS (':' : s) = "%3A" <> percentEncodeS s
354+percentEncodeS (';' : s) = "%3B" <> percentEncodeS s
355+percentEncodeS ('=' : s) = "%3D" <> percentEncodeS s
356+percentEncodeS ('?' : s) = "%3F" <> percentEncodeS s
357+percentEncodeS ('@' : s) = "%40" <> percentEncodeS s
358+percentEncodeS ('[' : s) = "%5B" <> percentEncodeS s
359+percentEncodeS (']' : s) = "%5D" <> percentEncodeS s
360+percentEncodeS (c : s) = c : percentEncodeS s
362+percentEncodeT :: Text -> Text
363+percentEncodeT = T.pack . percentEncodeS . T.unpack
365+percentDecodeS :: String -> String
366+percentDecodeS "" = ""
367+percentDecodeS ('%':'2':'1':s) = '!' : percentDecodeS s
368+percentDecodeS ('%':'2':'3':s) = '#' : percentDecodeS s
369+percentDecodeS ('%':'2':'4':s) = '$' : percentDecodeS s
370+percentDecodeS ('%':'2':'5':s) = '%' : percentDecodeS s
371+percentDecodeS ('%':'2':'6':s) = '&' : percentDecodeS s
372+percentDecodeS ('%':'2':'7':s) = '\'' : percentDecodeS s
373+percentDecodeS ('%':'2':'8':s) = '(' : percentDecodeS s
374+percentDecodeS ('%':'2':'9':s) = ')' : percentDecodeS s
375+percentDecodeS ('%':'2':'A':s) = '*' : percentDecodeS s
376+percentDecodeS ('%':'2':'B':s) = '+' : percentDecodeS s
377+percentDecodeS ('%':'2':'C':s) = ',' : percentDecodeS s
378+percentDecodeS ('%':'2':'F':s) = '/' : percentDecodeS s
379+percentDecodeS ('%':'3':'A':s) = ':' : percentDecodeS s
380+percentDecodeS ('%':'3':'B':s) = ';' : percentDecodeS s
381+percentDecodeS ('%':'3':'D':s) = '=' : percentDecodeS s
382+percentDecodeS ('%':'3':'F':s) = '?' : percentDecodeS s
383+percentDecodeS ('%':'4':'0':s) = '@' : percentDecodeS s
384+percentDecodeS ('%':'5':'B':s) = '[' : percentDecodeS s
385+percentDecodeS ('%':'5':'D':s) = ']' : percentDecodeS s
386+percentDecodeS (c : s) = c : percentDecodeS s
388+percentDecodeT :: Text -> Text
389+percentDecodeT = T.pack . percentDecodeS . T.unpack