FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Prevent API parse error when names contain quotes by fibbers · Pull Request #66 · ActiveCampaign/postmark-java · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or 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
Expand Up @@ -367,6 +367,10 @@ private String convertRecipients(List<String> recipients) {

private String convertRecipient(String name, String address) {
StringBuilder recipientsString = new StringBuilder();
if (name != null) {
// Escape characters that otherwise cause parsing errors in the API
name = name.replace("\"", "\\\"");
}
return recipientsString.append("\"").append(name).append("\"")
.append("<").append(address).append(">").toString();
}
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/unit/data/MessageTest.java
This file contains hidden or 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
Expand Up @@ -183,6 +183,28 @@ void simpleMessageBcccRecipientsFullName() throws IOException {

}

@Test
void recipientsWithQuotesAreEscapedProperly() {
Message message = new Message();
String nameWithQuote = "John \"Smith\"";
String email = "john@example.com";

Map<String, String> recipients = new HashMap<>();
recipients.put(nameWithQuote, email);

message.setTo(recipients);
assertEquals("\"John \\\"Smith\\\"\"<john@example.com>", message.getTo());

message.setCc(recipients);
assertEquals("\"John \\\"Smith\\\"\"<john@example.com>", message.getCc());

message.setBcc(recipients);
assertEquals("\"John \\\"Smith\\\"\"<john@example.com>", message.getBcc());

message.setFrom(nameWithQuote, email);
assertEquals("\"John \\\"Smith\\\"\"<john@example.com>", message.getFrom());
}

@Test
void attachmentException() throws IOException {
Message message = new Message();
Expand Down

Back | FazBrowse Home | New Git URL