-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: parsing of (text encoded) addresses
- Loading branch information
1 parent
ca2c329
commit 108d00e
Showing
4 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ module Data.IMF.Syntax | |
, crlf | ||
, vchar | ||
, word | ||
, dquote | ||
, quotedString | ||
, dotAtomText | ||
, dotAtom | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import Data.List.NonEmpty (NonEmpty((:|))) | |
import Data.String (IsString) | ||
import Data.Word (Word8) | ||
|
||
import qualified Data.Text as T | ||
import qualified Data.ByteString as B | ||
import qualified Data.ByteString.Lazy as L | ||
import qualified Data.ByteString.Lazy.Char8 as L8 | ||
|
@@ -47,6 +48,7 @@ renderField = Builder.toLazyByteString . buildField | |
unittests :: TestTree | ||
unittests = testGroup "Headers" | ||
[ parsesMailboxesSuccessfully | ||
, parsesMailboxesNonASCIISuccessfully | ||
, parsesTextMailboxesSuccessfully | ||
, parsesAddressesSuccessfully | ||
, parsesTextAddressesSuccessfully | ||
|
@@ -136,6 +138,26 @@ rendersAddressesToTextSuccessfully = | |
, "undisclosed-recipients:;") | ||
] | ||
|
||
nonASCIIDisplayNameFixtures :: IsString s => [(String, Either String Mailbox -> Assertion, s)] | ||
nonASCIIDisplayNameFixtures = | ||
[ | ||
( "Czech" | ||
, (Right (Mailbox (Just "Lud\283k Tiberiu") (AddrSpec "foo" (DomainDotAtom $ "bar" :| ["test"]))) @=?) | ||
, "Luděk Tiberiu") | ||
, ( "Chinese" | ||
, (Right (Mailbox (Just "佐藤 直樹") (AddrSpec "foo" (DomainDotAtom $ "bar" :| ["test"]))) @=?) | ||
, "佐藤 直樹") | ||
, ("Japanese" | ||
,(Right (Mailbox (Just "鈴木 一郎") (AddrSpec "foo" (DomainDotAtom $ "bar" :| ["test"]))) @=?) | ||
, "鈴木 一郎") | ||
, ("Korean" | ||
, (Right (Mailbox (Just "김철수") (AddrSpec "foo" (DomainDotAtom $ "bar" :| ["test"]))) @=?) | ||
, "김철수") | ||
, ("Apostrophy" | ||
, (Right (Mailbox (Just "O'Neill McCarthy") (AddrSpec "foo" (DomainDotAtom $ "bar" :| ["test"]))) @=?) | ||
, "O'Neill McCarthy") | ||
] | ||
|
||
-- | Note some examples are taken from https://tools.ietf.org/html/rfc3696#section-3 | ||
mailboxFixtures :: IsString s => [(String, Either String Mailbox -> Assertion, s)] | ||
mailboxFixtures = | ||
|
@@ -188,6 +210,14 @@ parsesMailboxesSuccessfully = | |
testCase desc $ f (AText.parseOnly AddressText.mailbox input)) <$> | ||
mailboxFixtures | ||
|
||
parsesMailboxesNonASCIISuccessfully :: TestTree | ||
parsesMailboxesNonASCIISuccessfully = | ||
testGroup "parsing mailboxes (nonASCII)" $ | ||
(\(desc, assertion, input) -> | ||
testCase desc $ assertion (AText.parseOnly AddressText.mailbox (input <> " <[email protected]>"))) <$> | ||
nonASCIIDisplayNameFixtures | ||
|
||
|
||
parsesTextMailboxesSuccessfully :: TestTree | ||
parsesTextMailboxesSuccessfully = | ||
testGroup "parsing mailboxes (text)" $ | ||
|