Permalink
Browse files

Preserve new lines unless they’re escaped using `=`

Also strip trailing `=` characters in encoded input.

Fixes #2.
  • Loading branch information...
mathiasbynens committed Jan 8, 2015
1 parent 58fe0dd commit fe1e3a47a26dfb710119b0d41e3fb6538a049f96
Showing with 20 additions and 12 deletions.
  1. +2 −2 README.md
  2. +4 −5 quoted-printable.js
  3. +4 −5 src/quoted-printable.js
  4. +10 −0 tests/tests.js
@@ -4,7 +4,7 @@ _quoted-printable_ is a character encoding–agnostic JavaScript implementation

## Installation

Via [npm](http://npmjs.org/):
Via [npm](https://www.npmjs.org/):

```bash
npm install quoted-printable
@@ -28,7 +28,7 @@ In a browser:
<script src="quoted-printable.js"></script>
```

In [Narwhal](http://narwhaljs.org/), [Node.js](http://nodejs.org/), and [RingoJS](http://ringojs.org/):
In [Narwhal](http://narwhaljs.org/), [Node.js](https://nodejs.org/), and [RingoJS](http://ringojs.org/):

```js
var quotedPrintable = require('quoted-printable');
@@ -25,11 +25,10 @@
// space on a line must be deleted, as it will necessarily have been added
// by intermediate transport agents.”
.replace(/[\t\x20]$/gm, '')
// Remove hard line breaks. Note: this includes `=` followed by a line
// break. Proper `Quoted-Printable`-encoded data only contains CRLF line
// endings, but for compatibility reasons we should support separate CR
// and LF too.
.replace(/=?(?:\r\n?|\n)/g, '')
// Remove hard line breaks preceded by `=`. Proper `Quoted-Printable`-
// encoded data only contains CRLF line endings, but for compatibility
// reasons we support separate CR and LF too.
.replace(/=(?:\r\n?|\n|$)/g, '')
// Decode escape sequences of the form `=XX` where `XX` is any
// combination of two hexidecimal digits. For optimal compatibility,
// lowercase hexadecimal digits are supported as well. See
@@ -25,11 +25,10 @@
// space on a line must be deleted, as it will necessarily have been added
// by intermediate transport agents.”
.replace(/[\t\x20]$/gm, '')
// Remove hard line breaks. Note: this includes `=` followed by a line
// break. Proper `Quoted-Printable`-encoded data only contains CRLF line
// endings, but for compatibility reasons we should support separate CR
// and LF too.
.replace(/=?(?:\r\n?|\n)/g, '')
// Remove hard line breaks preceded by `=`. Proper `Quoted-Printable`-
// encoded data only contains CRLF line endings, but for compatibility
// reasons we support separate CR and LF too.
.replace(/=(?:\r\n?|\n|$)/g, '')
// Decode escape sequences of the form `=XX` where `XX` is any
// combination of two hexidecimal digits. For optimal compatibility,
// lowercase hexadecimal digits are supported as well. See
@@ -145,6 +145,16 @@
'If you believe that truth=beauty, then surely mathematics is the most beautiful branch of philosophy.',
'Equals sign'
);
equal(
quotedPrintable.decode('foo\nbar'),
'foo\nbar',
'Hard new line characters'
);
equal(
quotedPrintable.decode('foo\r\nbar='),
'foo\r\nbar',
'Trailing ='
);
equal(
quotedPrintable.decode('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=\r\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=\r\nxx'),
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',

0 comments on commit fe1e3a4

Please sign in to comment.