Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to support parsing of "quoted-printable" encoded property values #31

Merged
merged 4 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/parse-lines.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function parseLines( lines ) {
// NOTE: Line format:
// PROPERTY[;PARAMETER[=VALUE]]:Attribute[;Attribute]
var line = null
var pattern = /^([^;:]+)((?:;(?:[^;:]+))*)(?:\:(.+))?$/i
var pattern = /^([^;:]+)((?:;(?:[^;:]+))*)(?:\:([\s\S]+))?$/i
var len = lines.length - 1

for( var i = 1; i < len; i++ ) {
Expand Down
2 changes: 1 addition & 1 deletion lib/vcard.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ vCard.prototype = {

// Normalize & split
var lines = vCard.normalize( value )
.split( /\r?\n/g )
.split( /\r\n/g )

// Keep begin and end markers
// for eventual error messages
Expand Down
7 changes: 7 additions & 0 deletions test/anomalies.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var vCard = require( '..' )
var fs = require( 'fs' )
var assert = require( 'assert' )
var vCard_withQuotedPrintableEncoding = require( './data/vcard-withQuotedPrintableEncoding' )

suite( 'vCard', function() {

Expand Down Expand Up @@ -31,6 +32,12 @@ suite( 'vCard', function() {
assert.deepEqual( card.get( 'tel' ).type, [ 'voice', 'home' ] )
})

test( 'should parse vCard property values containing isolated \\n without delimiting, e.g. used in quoted-printable encoding (issue #31)', function() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I meant Pullrequest #31, not Issue #31 ...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, no worries – issue and PR numbers don't overlap on GitHub, so it'll be found :)

var data = vCard_withQuotedPrintableEncoding;
var card = new vCard().parse( data );
assert.strictEqual(card.get( 'note' ).valueOf(), 'foobar foobar foobar foobar fo=\nobar foobar foobar foobar foobar=0Afoobar foobar foobar foobar foobar fooba=\nr=0Afoobar foobar foobar foobar foobar foobar=0Afoobar foobar foobar foobar=\n foobar foobar foobar foobar foobar')
})

})

})
22 changes: 22 additions & 0 deletions test/data/vcard-withQuotedPrintableEncoding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports =
'BEGIN:VCARD\r\n' +
'VERSION:4.0\r\n' +
'N:Gump;Forrest;;;\r\n' +
'FN:Forrest Gump\r\n' +
'ORG:Bubba Gump Shrimp Co.\r\n' +
'TITLE:Shrimp Man\r\n' +
'PHOTO;MEDIATYPE=image/gif:http://www.example.com/dir_photos/my_photo.gif\r\n' +
'TEL;TYPE=work,voice;VALUE=uri:tel:+11115551212\r\n' +
'TEL;TYPE=home,voice;VALUE=uri:tel:+14045551212\r\n' +
'item1.TEL;TYPE=home,voice;VALUE=uri:tel:+14045551213\r\n' +
'ADR;TYPE=work;LABEL="100 Waters Edge\\nBaytown, LA 30314\\nUnited States of A\r\n' +
' merica":;;100 Waters Edge;Baytown;LA;30314;United States of America\r\n' +
'ADR;TYPE=home;LABEL="42 Plantation St.\\nBaytown, LA 30314\\nUnited States of\r\n' +
' America":;;42 Plantation St.;Baytown;LA;30314;United States of America\r\n' +
'EMAIL:forrestgump@example.com\r\n' +
'NOTE;ENCODING=QUOTED-PRINTABLE;CHARSET=utf-8:foobar foobar foobar foobar fo=\n' +
'obar foobar foobar foobar foobar=0Afoobar foobar foobar foobar foobar fooba=\n' +
'r=0Afoobar foobar foobar foobar foobar foobar=0Afoobar foobar foobar foobar=\n' +
' foobar foobar foobar foobar foobar\r\n' +
'REV:20080424T195243Z\r\n' +
'END:VCARD\r\n';