Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/amazonka-core/src/Amazonka/Data/Time.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,20 @@ parseFormattedTime = do
++ show s
)

parse (format (Proxy @RFC822))
-- A more lenient format string for parsing RFC822, whose
-- grammar allows single-digit days.
--
-- We still use `%d` over `%-d` in the `TimeFormat RFC822`
-- instance to always produce two-digit days, since that is what
-- most people expect to see.
--
-- This allows us to parse responses from versions of
-- `rclone serve s3` circa 2024:
-- https://github.com/rclone/rclone/issues/8277
rfc822 :: String
rfc822 = "%a, %-d %b %Y %H:%M:%S %Z"

parse rfc822
<|> parse (format (Proxy @ISO8601))
<|> parse (format (Proxy @BasicTime))
<|> parse (format (Proxy @AWSTime))
Expand Down Expand Up @@ -138,7 +151,7 @@ instance ToText AWSTime where
instance ToText POSIX where
toText (Time t) = toText (truncate (utcTimeToPOSIXSeconds t) :: Integer)

renderFormattedTime :: forall a. TimeFormat (Time a) => Time a -> String
renderFormattedTime :: forall a. (TimeFormat (Time a)) => Time a -> String
renderFormattedTime (Time t) =
formatTime
defaultTimeLocale
Expand Down
4 changes: 4 additions & 0 deletions lib/amazonka-core/test/Test/Amazonka/Data/Time.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ tests =
"rfc822 - GMT"
"Fri, 07 Nov 2014 04:42:13 GMT"
(time :: RFC822),
testFromText
"rfc822 - GMT - single-digit day"
"Fri, 7 Nov 2014 04:42:13 GMT"
(time :: RFC822),
testFromText
"rfc822 - PST"
"Fri, 06 Nov 2014 20:42:13 PST"
Expand Down
24 changes: 12 additions & 12 deletions lib/amazonka-core/test/Test/Amazonka/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ doc =
newtype X a = X a
deriving stock (Eq, Show)

instance ToQuery a => ToQuery (X a) where
instance (ToQuery a) => ToQuery (X a) where
toQuery (X x) = "x" =: x

instance FromXML a => FromXML (X a) where
instance (FromXML a) => FromXML (X a) where
parseXML = fmap X . parseXML

instance ToXML a => ToElement (X a) where
instance (ToXML a) => ToElement (X a) where
toElement (X x) = mkElement "x" x

instance FromJSON a => FromJSON (X a) where
instance (FromJSON a) => FromJSON (X a) where
parseJSON = withObject "X" (fmap X . (.: "x"))

instance ToJSON a => ToJSON (X a) where
instance (ToJSON a) => ToJSON (X a) where
toJSON (X x) = object ["x" .= x]

testFromText ::
Expand All @@ -50,15 +50,15 @@ testFromText ::
Text ->
a ->
TestTree
testFromText n t x = testCase n (Right x @?= fromText t)
testFromText n t x = testCase n (Right x @=? fromText t)

testToText ::
(ToText a, Show a, Eq a) =>
TestName ->
Text ->
a ->
TestTree
testToText n t x = testCase n (t @?= toText x)
testToText n t x = testCase n (t @=? toText x)

testToQuery ::
(ToQuery a, Show a, Eq a) =>
Expand All @@ -76,15 +76,15 @@ testFromXML ::
TestTree
testFromXML n bs x =
testCase n $
Right (X x) @?= (decodeXML (wrapXML bs) >>= parseXML)
(decodeXML (wrapXML bs) >>= parseXML) @=? Right (X x)

testToXML ::
(ToXML a, Show a, Eq a) =>
TestName ->
ByteStringLazy ->
a ->
TestTree
testToXML n bs x = testCase n $ wrapXML bs @?= encodeXML (X x)
testToXML n bs x = testCase n $ wrapXML bs @=? encodeXML (X x)

testFromJSON ::
(FromJSON a, Show a, Eq a) =>
Expand All @@ -94,15 +94,15 @@ testFromJSON ::
TestTree
testFromJSON n bs x =
testCase n $
Right (X x) @?= eitherDecode' ("{\"x\":" <> bs <> "}")
eitherDecode' ("{\"x\":" <> bs <> "}") @=? Right (X x)

testToJSON ::
(ToJSON a, Show a, Eq a) =>
TestName ->
ByteStringLazy ->
a ->
TestTree
testToJSON n bs x = testCase n (bs @?= Aeson.encode x)
testToJSON n bs x = testCase n (bs @=? Aeson.encode x)

str :: ByteStringLazy -> ByteStringLazy
str bs = "\"" <> bs <> "\""
Expand All @@ -117,5 +117,5 @@ maxInt = maxBound
minInt :: Int
minInt = minBound

toLazyBS :: ToByteString a => a -> ByteStringLazy
toLazyBS :: (ToByteString a) => a -> ByteStringLazy
toLazyBS = LBS.fromStrict . toBS
2 changes: 2 additions & 0 deletions lib/amazonka/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

### Fixed

- `amazonka-core`: Accept single-digit days when parsing RFC822 dates
[\#1032](https://github.com/brendanhay/amazonka/pull/1032)
- `amazonka-core`: Fixed the sorting of query parameters during request canonicalisation. In rare cases, it could sort incorrectly, resulting in requests that failed signature verification.
[\#1031](https://github.com/brendanhay/amazonka/pull/1031)
- `amazonka`: Attempt to load credentials in the correct order. In particular, this means that the IMDS is queried last and is once again consistent with other SDKs.
Expand Down
Loading