From ef006fd1b58e7c7a40c233f27b5efc0a10e7a840 Mon Sep 17 00:00:00 2001 From: James Emerton Date: Sun, 5 Oct 2014 10:06:22 -0700 Subject: [PATCH] Automatically format CAL-ADDRESS with mailto: prefix --- lib/types.js | 7 ++++++- spec/types-spec.js | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/types.js b/lib/types.js index 2025c56..2af4fd7 100644 --- a/lib/types.js +++ b/lib/types.js @@ -50,7 +50,12 @@ var _types = { } }, 'CAL-ADDRESS': { - format: function(value) { return value.toString(); } + format: function(value) { + var v = value.toString(); + if(v.lastIndexOf("mailto:") != 0) + v = "mailto:"+v; + return v; + } }, 'DATE': { format: function(value) { diff --git a/spec/types-spec.js b/spec/types-spec.js index e43a3cd..23965c7 100644 --- a/spec/types-spec.js +++ b/spec/types-spec.js @@ -60,6 +60,13 @@ describe('iCalendar type formatters and parsers', function() { }); + it('automatically prepends mailto: for CAL-ADDRESS properties', function() { + expect(icalendar.format_value('CAL-ADDRESS', 'bob@example.com')) + .toEqual('mailto:bob@example.com'); + expect(icalendar.format_value('CAL-ADDRESS', 'mailto:bob@example.com')) + .toEqual('mailto:bob@example.com'); + }); + it('value parsers', function() { assert.equal('\u0000\u0001\u0002\u0004\u0005\u0006', icalendar.parse_value('BINARY', 'AAECBAUG'));