Skip to content

quoted_printable_encode does not encode trailing space #24458

Open

Description

@Sjord

Description

The following code:

<?php
var_dump(quoted_printable_encode('hello '));

Resulted in this output:

string(6) "hello "

But I expected this output instead:

string(9) "hello=20"

RFC 2045 says:

(3)   (White Space) Octets with values of 9 and 32 MAY be
      represented as US-ASCII TAB (HT) and SPACE characters,
      respectively, but MUST NOT be so represented at the end
      of an encoded line.  Any TAB (HT) or SPACE characters
      on an encoded line MUST thus be followed on that line
      by a printable character.  In particular, an "=" at the
      end of an encoded line, indicating a soft line break
      (see rule #5) may follow one or more TAB (HT) or SPACE
      characters.  It follows that an octet with decimal
      value 9 or 32 appearing at the end of an encoded line
      must be represented according to Rule #1.  This rule is
      necessary because some MTAs (Message Transport Agents,
      programs which transport messages from one user to
      another, or perform a portion of such transfers) are
      known to pad lines of text with SPACEs, and others are
      known to remove "white space" characters from the end
      of a line.  Therefore, when decoding a Quoted-Printable
      body, any trailing white space on a line must be
      deleted, as it will necessarily have been added by
      intermediate transport agents.

PHP Version

PHP 8.7.0-dev (cli) (built: Oct 18 2026 16:29:33) (NTS DEBUG)
Copyright © The PHP Group and Contributors
Zend Engine v4.7.0-dev, Copyright © Zend by Perforce
    with Zend OPcache v8.7.0-dev, Copyright ©, by Zend by Perforce

Operating System

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions