aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/caldav/sax/dav_response.js4
-rw-r--r--lib/ical.js152
-rw-r--r--lib/sax.js2
-rw-r--r--test/caldav/ical_test.js2
-rw-r--r--test/caldav/sax/dav_response_test.js2
-rw-r--r--test/caldav/xhr_test.js3
6 files changed, 102 insertions, 63 deletions
diff --git a/lib/caldav/sax/dav_response.js b/lib/caldav/sax/dav_response.js
index ef84f66..0957376 100644
--- a/lib/caldav/sax/dav_response.js
+++ b/lib/caldav/sax/dav_response.js
@@ -1,5 +1,9 @@
(function(module, ns) {
+ if (typeof(ICAL) === 'undefined') {
+ require('../../ical.js');
+ }
+
var HTTP_STATUS = /([0-9]{3,3})/;
var Base = ns.require('sax/base');
diff --git a/lib/ical.js b/lib/ical.js
index 0c34e34..5c7d740 100644
--- a/lib/ical.js
+++ b/lib/ical.js
@@ -1,7 +1,10 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-(typeof(ICAL) === 'undefined')? ICAL = {} : '';
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ * Portions Copyright (C) Philipp Kewisch, 2011-2012 */
+
+if (typeof(ICAL) === 'undefined')
+ (typeof(window) !== 'undefined') ? this.ICAL = {} : ICAL = {};
/**
* Helper functions used in various places within ical.js
@@ -28,7 +31,7 @@ ICAL.helpers = {
dumpn: function() {
if (!ICAL.debug) {
- return null;
+ return;
}
if (typeof (console) !== 'undefined' && 'log' in console) {
@@ -53,6 +56,39 @@ ICAL.helpers = {
return obj;
},
+ isArray: function(o) {
+ return o && (o instanceof Array || typeof o == "array");
+ },
+
+ clone: function(aSrc, aDeep) {
+ if (!aSrc || typeof aSrc != "object") {
+ return aSrc;
+ } else if (aSrc instanceof Date) {
+ return new Date(aSrc.getTime());
+ } else if ("clone" in aSrc) {
+ return aSrc.clone();
+ } else if (ICAL.helpers.isArray(aSrc)) {
+ var result = [];
+ for (var i = 0; i < aSrc.length; i++) {
+ result.push(aDeep ? ICAL.helpers.clone(aSrc[i], true) : aSrc[i]);
+ }
+ return result;
+ } else {
+ var result = {};
+ for (var name in aSrc) {
+ if (aSrc.hasOwnProperty(name)) {
+ dump("Cloning " + name + "\n");
+ if (aDeep) {
+ result[name] = ICAL.helpers.clone(aSrc[name], true);
+ } else {
+ result[name] = aSrc[name];
+ }
+ }
+ }
+ return result;
+ }
+ },
+
unfoldline: function unfoldline(aState) {
// Section 3.1
// if the line ends with a CRLF
@@ -139,8 +175,10 @@ ICAL.helpers = {
};
}());
/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ * Portions Copyright (C) Philipp Kewisch, 2011-2012 */
+
// TODO validate known parameters
// TODO make sure all known types don't contain junk
// TODO tests for parsers
@@ -257,7 +295,7 @@ ICAL.helpers = {
var match = parser.expectRE(aState, /^X-/, error);
// Vendor ID
- if ((match = parser.expectOptionalRE(aState, /^([A-Za-z0-9]+-)/, error))) {
+ if (match = parser.expectOptionalRE(aState, /^([A-Za-z0-9]+-)/, error)) {
value += match[1];
}
@@ -903,10 +941,6 @@ ICAL.helpers = {
};
parser.parseUtcOffset = function parseUtcOffset(aState) {
- if (aState.buffer == "-0000" || aState.buffer == "-000000") {
- throw new ParserError(aState,
- "Invalid value for utc offset: " + aState.buffer);
- }
var utcRE = /^(([+-])([01][0-9]|2[0-3])([0-5][0-9])([0-5][0-9])?)$/;
var match = parser.expectRE(aState, utcRE, "Expected valid utc offset");
return {
@@ -1032,8 +1066,10 @@ ICAL.helpers = {
*/
})();
/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ * Portions Copyright (C) Philipp Kewisch, 2011-2012 */
+
(typeof(ICAL) === 'undefined')? ICAL = {} : '';
/**
@@ -1410,10 +1446,11 @@ ICAL.design = {
}
};
/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ * Portions Copyright (C) Philipp Kewisch, 2011-2012 */
+"use strict";
(typeof(ICAL) === 'undefined')? ICAL = {} : '';
(function() {
@@ -1696,10 +1733,11 @@ ICAL.design = {
};
})();
/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ * Portions Copyright (C) Philipp Kewisch, 2011-2012 */
+"use strict";
(typeof(ICAL) === 'undefined')? ICAL = {} : '';
(function() {
@@ -1883,10 +1921,11 @@ ICAL.design = {
};
})();
/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ * Portions Copyright (C) Philipp Kewisch, 2011-2012 */
+"use strict";
(typeof(ICAL) === 'undefined')? ICAL = {} : '';
(function() {
@@ -2099,10 +2138,11 @@ ICAL.design = {
ICAL.icalvalue._createFromString(ICAL.icalutcoffset);
})();
/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ * Portions Copyright (C) Philipp Kewisch, 2011-2012 */
+"use strict";
(typeof(ICAL) === 'undefined')? ICAL = {} : '';
(function() {
@@ -2149,10 +2189,11 @@ ICAL.design = {
};
})();
/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ * Portions Copyright (C) Philipp Kewisch, 2011-2012 */
+"use strict";
(typeof(ICAL) === 'undefined')? ICAL = {} : '';
(function() {
@@ -2280,10 +2321,11 @@ ICAL.design = {
};
})();
/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ * Portions Copyright (C) Philipp Kewisch, 2011-2012 */
+"use strict";
(typeof(ICAL) === 'undefined')? ICAL = {} : '';
(function() {
@@ -2326,10 +2368,8 @@ ICAL.design = {
if (aData && "component" in aData) {
if (typeof aData.component == "string") {
this.component = this.componentFromString(aData.component);
- } else if (aData.component.icalclass == "icalcomponent") {
- this.component = aData.component.clone();
} else {
- this.component = eval(aData.component.toSource());
+ this.component = ICAL.helpers.clone(aData.component, true);
}
} else {
this.component = null;
@@ -2367,9 +2407,7 @@ ICAL.design = {
var step = 1;
for (;;) {
- //TODO: we should not use eval anywhere and
- // this only works in gecko (toSource)
- var change = eval(this.changes[change_num].toSource()); // TODO clone
+ var change = ICAL.helpers.clone(this.changes[change_num], true);
if (change.utc_offset < change.prev_utc_offset) {
ICAL.helpers.dumpn("Adjusting " + change.utc_offset);
ICAL.icaltimezone.adjust_change(change, 0, 0, 0, change.utc_offset);
@@ -2407,9 +2445,7 @@ ICAL.design = {
var utc_offset_change = zone_change.utc_offset - zone_change.prev_utc_offset;
if (utc_offset_change < 0 && change_num_to_use > 0) {
- //TODO: we should not use eval anywhere and
- // this only works in gecko (toSource)
- var tmp_change = eval(zone_change.toSource()); // TODO copy
+ var tmp_change = ICAL.helpers.clone(zone_change, true);
ICAL.icaltimezone.adjust_change(tmp_change, 0, 0, 0,
tmp_change.prev_utc_offset);
@@ -2493,7 +2529,7 @@ ICAL.design = {
if (!aComponent.hasProperty("DTSTART") ||
!aComponent.hasProperty("TZOFFSETTO") ||
!aComponent.hasProperty("TZOFFSETFROM")) {
- return null;
+ return;
}
var dtstart = aComponent.getFirstProperty("DTSTART").getFirstValue();
@@ -2627,8 +2663,6 @@ ICAL.design = {
utc_offset = to_zone.utc_offset(tt);
tt.adjust(0, 0, 0, utc_offset);
-
- return null;
};
ICAL.icaltimezone.fromData = function icaltimezone_fromData(aData) {
@@ -2652,10 +2686,11 @@ ICAL.design = {
ICAL.icaltimezone.EXTRA_COVERAGE = 5;
})();
/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ * Portions Copyright (C) Philipp Kewisch, 2011-2012 */
+"use strict";
(typeof(ICAL) === 'undefined')? ICAL = {} : '';
(function() {
@@ -3372,10 +3407,11 @@ ICAL.design = {
ICAL.icaltime.SATURDAY = 7;
})();
/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ * Portions Copyright (C) Philipp Kewisch, 2011-2012 */
+"use strict";
(typeof(ICAL) === 'undefined')? ICAL = {} : '';
(function() {
@@ -3521,15 +3557,12 @@ ICAL.design = {
} catch (e) {
ICAL.helpers.dumpn("EICALPROP: " + this.toString() + "//" + e);
ICAL.helpers.dumpn(e.stack);
- return null;
}
},
fromIcalProperty: function fromIcalProperty(aProp) {
var propval = aProp.getFirstValue();
this.fromData(propval);
- //TODO: we should not use eval anywhere and
- // this only works in gecko (toSource)
- this.parts = eval(propval.parts.toSource());
+ this.parts = ICAL.helpers.clone(propval.parts, true);
if (aProp.name == "EXRULE") {
this.isNegative = true;
} else if (aProp.name == "RRULE") {
@@ -3558,9 +3591,7 @@ ICAL.design = {
function icalrecur_iterator(aRule, aStart) {
this.rule = aRule;
this.dtstart = aStart;
- //TODO: we should not use eval anywhere and
- // this only works in gecko (toSource)
- this.by_data = eval(aRule.parts.toSource());
+ this.by_data = ICAL.helpers.clone(aRule.parts, true);
this.days = [];
this.init();
}
@@ -3637,7 +3668,7 @@ ICAL.design = {
if (this.rule.freq == "WEEKLY") {
if ("BYDAY" in parts) {
- var parts = this.this.rule_day_of_week(parts.BYDAY[0]);
+ var parts = this.rule_day_of_week(parts.BYDAY[0]);
var pos = parts[0];
var rule_dow = parts[1];
var dow = rule_dow - this.last.day_of_week();
@@ -4526,10 +4557,11 @@ ICAL.design = {
icalrecur_iterator.ILLEGAL = 3;
})();
/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ * Portions Copyright (C) Philipp Kewisch, 2011-2012 */
+"use strict";
(typeof(ICAL) === 'undefined')? ICAL = {} : '';
diff --git a/lib/sax.js b/lib/sax.js
index 63ae844..1808efa 100644
--- a/lib/sax.js
+++ b/lib/sax.js
@@ -993,5 +993,5 @@ function write (chunk) {
return parser
}
-})(typeof exports === "undefined" ? sax = {} : exports)
+})(typeof exports === "undefined" ? this.sax = {} : exports)
diff --git a/test/caldav/ical_test.js b/test/caldav/ical_test.js
index f2bc8b9..561bad3 100644
--- a/test/caldav/ical_test.js
+++ b/test/caldav/ical_test.js
@@ -1,4 +1,4 @@
-require('/lib/ical.js');
+testSupport.lib('../ical');
suite('caldav/ics', function() {
diff --git a/test/caldav/sax/dav_response_test.js b/test/caldav/sax/dav_response_test.js
index cb3d2b7..b8f4716 100644
--- a/test/caldav/sax/dav_response_test.js
+++ b/test/caldav/sax/dav_response_test.js
@@ -3,7 +3,7 @@ testSupport.lib('sax');
testSupport.lib('sax/base');
testSupport.lib('ical');
testSupport.lib('sax/dav_response');
-require('/lib/ical.js');
+testSupport.lib('../ical');
suite('caldav/sax/dav_response', function() {
diff --git a/test/caldav/xhr_test.js b/test/caldav/xhr_test.js
index c71dc12..0d6d7fb 100644
--- a/test/caldav/xhr_test.js
+++ b/test/caldav/xhr_test.js
@@ -137,6 +137,9 @@ suite('webacls/xhr', function() {
});
test('with mozSystem', function() {
+ if (typeof(window) === 'undefined')
+ return;
+
var user = 'user';
var password = 'pass';
var url = '/foo';