Skip to content

Apostrophe in Subject Not Parsing Properly #602

Description

@JamesTheTerry

Issue Summary

I've been sending subjects with apostrophes and quotation marks and they've appeared with HTML encoding: " and '

I've tried encoding it straight strign, with utf_8 encoding, and with utf_8 encoding then decoded for unicode_escape.

When tried in the API explorer it worked fine, with the characters appearing as they should.

An example: subject = "Test: \" Charle's - James\'s - chr: " + chr(39) is received as:
Test: " Charle's - James's - chr: '

Steps to Reproduce

import sendgrid
from sendgrid.helpers.mail import *

SENDGRID_API_KEY = 'XXX'
sg = sendgrid.SendGridAPIClient(apikey=SENDGRID_API_KEY)
OUTGOING_EMAIL = 'sender@example.com'
OUTGOING_EMAIL_NAME = 'Mr Example'
SENDGRID_TEMPLATE_ID = 'TEMPLATE'

def sendEmail(to_email, subject, content):
    """ Sends email via sendgrid """
    data = {
        "personalizations": [
            {
                "to": [
                    {
                        "email": to_email
                    }
                ],
                "dynamic_template_data": {
                    "subject": subject,
                    "content": content
                },
            }
        ],
        "from": {
            "email": OUTGOING_EMAIL,
            "name": OUTGOING_EMAIL_NAME
        },
        "reply_to": {
            "email": "noreply@example.com",
            "name": "No Reply"
        },
        "template_id": SENDGRID_TEMPLATE_ID
    }

    response = sg.client.mail.send.post(request_body=data)
    print(response.status_code)
    print(response.body)
    print(response.headers)


# Test content goes here
to_email = 'me@example.com'
subject = "Test: \" Charle's - James\'s - chr: " + chr(39)
subject_utf8 = subject.encode("utf_8").decode("unicode_escape")
content = ["Just testing out apostrophes", "Without escape: ' here", 'With esacpe: \' here']

sendEmail(to_email, subject, content)
sendEmail(to_email, subject_utf8, content)

Technical details:

  • sendgrid-python Version: 5.4.1
  • Python Version: 2.7.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions