Skip to content
Snippets Groups Projects
onDeleteAccount.js 7.96 MiB
Newer Older
  • Learn to ignore specific revisions
  • Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000
                module.children = originalModuleChildren; // Removes last references to modules required in callbackForModulesToKeep() -> No memory leak
            }
    
            // Takes the cache entries of the original cache in case the modules where required before
            for ( var i = 0; i < modulesToKeep.length; i+=1 ) {
                if (originalCache[modulesToKeep[i]]) {
                    requireCache[modulesToKeep[i]] = originalCache[modulesToKeep[i]];
                }
            }
    
        }
    
        var freshModule = callback();
    
        var stealthCache = callbackForModulesToKeep ? assign({}, requireCache) : false;
    
        clearCache(requireCache);
    
        if (callbackForModulesToKeep) {
            // In case modules to keep were required inside the stealthy require for the first time, copy them to the restored cache
            for ( var k = 0; k < modulesToKeep.length; k+=1 ) {
                if (stealthCache[modulesToKeep[k]]) {
                    requireCache[modulesToKeep[k]] = stealthCache[modulesToKeep[k]];
                }
            }
        }
    
        assign(requireCache, originalCache);
    
        return freshModule;
    
    };
    
    
    /***/ }),
    /* 58 */
    /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
    
    "use strict";
    // Copyright 2010-2012 Mikeal Rogers
    //
    //    Licensed under the Apache License, Version 2.0 (the "License");
    //    you may not use this file except in compliance with the License.
    //    You may obtain a copy of the License at
    //
    //        http://www.apache.org/licenses/LICENSE-2.0
    //
    //    Unless required by applicable law or agreed to in writing, software
    //    distributed under the License is distributed on an "AS IS" BASIS,
    //    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    //    See the License for the specific language governing permissions and
    //    limitations under the License.
    
    
    
    var extend = __webpack_require__(59)
    var cookies = __webpack_require__(60)
    var helpers = __webpack_require__(74)
    
    var paramsHaveRequestBody = helpers.paramsHaveRequestBody
    
    // organize params for patch, post, put, head, del
    function initParams (uri, options, callback) {
      if (typeof options === 'function') {
        callback = options
      }
    
      var params = {}
      if (options !== null && typeof options === 'object') {
        extend(params, options, {uri: uri})
      } else if (typeof uri === 'string') {
        extend(params, {uri: uri})
      } else {
        extend(params, uri)
      }
    
      params.callback = callback || params.callback
      return params
    }
    
    function request (uri, options, callback) {
      if (typeof uri === 'undefined') {
        throw new Error('undefined is not a valid uri or options object.')
      }
    
      var params = initParams(uri, options, callback)
    
      if (params.method === 'HEAD' && paramsHaveRequestBody(params)) {
        throw new Error('HTTP HEAD requests MUST NOT include a request body.')
      }
    
      return new request.Request(params)
    }
    
    function verbFunc (verb) {
      var method = verb.toUpperCase()
      return function (uri, options, callback) {
        var params = initParams(uri, options, callback)
        params.method = method
        return request(params, params.callback)
      }
    }
    
    // define like this to please codeintel/intellisense IDEs
    request.get = verbFunc('get')
    request.head = verbFunc('head')
    request.options = verbFunc('options')
    request.post = verbFunc('post')
    request.put = verbFunc('put')
    request.patch = verbFunc('patch')
    request.del = verbFunc('delete')
    request['delete'] = verbFunc('delete')
    
    request.jar = function (store) {
      return cookies.jar(store)
    }
    
    request.cookie = function (str) {
      return cookies.parse(str)
    }
    
    function wrapRequestMethod (method, options, requester, verb) {
      return function (uri, opts, callback) {
        var params = initParams(uri, opts, callback)
    
        var target = {}
        extend(true, target, options, params)
    
        target.pool = params.pool || options.pool
    
        if (verb) {
          target.method = verb.toUpperCase()
        }
    
        if (typeof requester === 'function') {
          method = requester
        }
    
        return method(target, target.callback)
      }
    }
    
    request.defaults = function (options, requester) {
      var self = this
    
      options = options || {}
    
      if (typeof options === 'function') {
        requester = options
        options = {}
      }
    
      var defaults = wrapRequestMethod(self, options, requester)
    
      var verbs = ['get', 'head', 'post', 'put', 'patch', 'del', 'delete']
      verbs.forEach(function (verb) {
        defaults[verb] = wrapRequestMethod(self[verb], options, requester, verb)
      })
    
      defaults.cookie = wrapRequestMethod(self.cookie, options, requester)
      defaults.jar = self.jar
      defaults.defaults = self.defaults
      return defaults
    }
    
    request.forever = function (agentOptions, optionsArg) {
      var options = {}
      if (optionsArg) {
        extend(options, optionsArg)
      }
      if (agentOptions) {
        options.agentOptions = agentOptions
      }
    
      options.forever = true
      return request.defaults(options)
    }
    
    // Exports
    
    module.exports = request
    request.Request = __webpack_require__(79)
    request.initParams = initParams
    
    // Backwards compatibility for request.debug
    Object.defineProperty(request, 'debug', {
      enumerable: true,
      get: function () {
        return request.Request.debug
      },
      set: function (debug) {
        request.Request.debug = debug
      }
    })
    
    
    /***/ }),
    /* 59 */
    /***/ ((module) => {
    
    "use strict";
    
    
    var hasOwn = Object.prototype.hasOwnProperty;
    var toStr = Object.prototype.toString;
    var defineProperty = Object.defineProperty;
    var gOPD = Object.getOwnPropertyDescriptor;
    
    var isArray = function isArray(arr) {
    	if (typeof Array.isArray === 'function') {
    		return Array.isArray(arr);
    	}
    
    	return toStr.call(arr) === '[object Array]';
    };
    
    var isPlainObject = function isPlainObject(obj) {
    	if (!obj || toStr.call(obj) !== '[object Object]') {
    		return false;
    	}
    
    	var hasOwnConstructor = hasOwn.call(obj, 'constructor');
    	var hasIsPrototypeOf = obj.constructor && obj.constructor.prototype && hasOwn.call(obj.constructor.prototype, 'isPrototypeOf');
    	// Not own constructor property must be Object
    	if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) {
    		return false;
    	}
    
    	// Own properties are enumerated firstly, so to speed up,
    	// if last one is own, then all properties are own.
    	var key;
    	for (key in obj) { /**/ }
    
    	return typeof key === 'undefined' || hasOwn.call(obj, key);
    };
    
    // If name is '__proto__', and Object.defineProperty is available, define __proto__ as an own property on target
    var setProperty = function setProperty(target, options) {
    	if (defineProperty && options.name === '__proto__') {
    		defineProperty(target, options.name, {
    			enumerable: true,
    			configurable: true,
    			value: options.newValue,
    			writable: true
    		});
    	} else {
    		target[options.name] = options.newValue;
    	}
    };
    
    // Return undefined instead of __proto__ if '__proto__' is not an own property
    var getProperty = function getProperty(obj, name) {
    	if (name === '__proto__') {
    		if (!hasOwn.call(obj, name)) {
    			return void 0;
    		} else if (gOPD) {
    			// In early versions of node, obj['__proto__'] is buggy when obj has
    			// __proto__ as an own property. Object.getOwnPropertyDescriptor() works.
    			return gOPD(obj, name).value;
    		}
    	}
    
    	return obj[name];
    };
    
    module.exports = function extend() {
    	var options, name, src, copy, copyIsArray, clone;
    	var target = arguments[0];
    	var i = 1;
    	var length = arguments.length;
    	var deep = false;
    
    	// Handle a deep copy situation
    	if (typeof target === 'boolean') {
    		deep = target;
    		target = arguments[1] || {};
    		// skip the boolean and the target
    		i = 2;
    	}
    	if (target == null || (typeof target !== 'object' && typeof target !== 'function')) {
    		target = {};
    	}
    
    	for (; i < length; ++i) {
    		options = arguments[i];
    		// Only deal with non-null/undefined values
    		if (options != null) {
    			// Extend the base object
    			for (name in options) {
    				src = getProperty(target, name);
    				copy = getProperty(options, name);
    
    				// Prevent never-ending loop
    				if (target !== copy) {
    					// Recurse if we're merging plain objects or arrays
    					if (deep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) {
    						if (copyIsArray) {
    							copyIsArray = false;
    							clone = src && isArray(src) ? src : [];
    						} else {
    							clone = src && isPlainObject(src) ? src : {};
    						}
    
    						// Never move original objects, clone them
    						setProperty(target, { name: name, newValue: extend(deep, clone, copy) });
    
    					// Don't bring in undefined values
    					} else if (typeof copy !== 'undefined') {
    						setProperty(target, { name: name, newValue: copy });
    					}
    				}
    			}
    		}
    	}
    
    	// Return the modified object
    	return target;
    };
    
    
    /***/ }),
    /* 60 */
    /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
    
    "use strict";
    
    
    var tough = __webpack_require__(61)
    
    var Cookie = tough.Cookie
    var CookieJar = tough.CookieJar
    
    exports.parse = function (str) {
      if (str && str.uri) {
        str = str.uri
      }
      if (typeof str !== 'string') {
        throw new Error('The cookie function only accepts STRING as param')
      }
      return Cookie.parse(str, {loose: true})
    }
    
    // Adapt the sometimes-Async api of tough.CookieJar to our requirements
    function RequestJar (store) {
      var self = this
      self._jar = new CookieJar(store, {looseMode: true})
    }
    RequestJar.prototype.setCookie = function (cookieOrStr, uri, options) {
      var self = this
      return self._jar.setCookieSync(cookieOrStr, uri, options || {})
    }
    RequestJar.prototype.getCookieString = function (uri) {
      var self = this
      return self._jar.getCookieStringSync(uri)
    }
    RequestJar.prototype.getCookies = function (uri) {
      var self = this
      return self._jar.getCookiesSync(uri)
    }
    
    exports.jar = function (store) {
      return new RequestJar(store)
    }
    
    
    /***/ }),
    /* 61 */
    /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
    
    "use strict";
    /*!
     * Copyright (c) 2015, Salesforce.com, Inc.
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice,
     * this list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form must reproduce the above copyright notice,
     * this list of conditions and the following disclaimer in the documentation
     * and/or other materials provided with the distribution.
     *
     * 3. Neither the name of Salesforce.com nor the names of its contributors may
     * be used to endorse or promote products derived from this software without
     * specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     * POSSIBILITY OF SUCH DAMAGE.
     */
    
    var net = __webpack_require__(62);
    var urlParse = (__webpack_require__(63).parse);
    var util = __webpack_require__(64);
    var pubsuffix = __webpack_require__(65);
    var Store = (__webpack_require__(69).Store);
    var MemoryCookieStore = (__webpack_require__(70).MemoryCookieStore);
    var pathMatch = (__webpack_require__(72).pathMatch);
    var VERSION = __webpack_require__(73);
    
    var punycode;
    try {
      punycode = __webpack_require__(67);
    } catch(e) {
      console.warn("tough-cookie: can't load punycode; won't use punycode for domain normalization");
    }
    
    // From RFC6265 S4.1.1
    // note that it excludes \x3B ";"
    var COOKIE_OCTETS = /^[\x21\x23-\x2B\x2D-\x3A\x3C-\x5B\x5D-\x7E]+$/;
    
    var CONTROL_CHARS = /[\x00-\x1F]/;
    
    // From Chromium // '\r', '\n' and '\0' should be treated as a terminator in
    // the "relaxed" mode, see:
    // https://github.com/ChromiumWebApps/chromium/blob/b3d3b4da8bb94c1b2e061600df106d590fda3620/net/cookies/parsed_cookie.cc#L60
    var TERMINATORS = ['\n', '\r', '\0'];
    
    // RFC6265 S4.1.1 defines path value as 'any CHAR except CTLs or ";"'
    // Note ';' is \x3B
    var PATH_VALUE = /[\x20-\x3A\x3C-\x7E]+/;
    
    // date-time parsing constants (RFC6265 S5.1.1)
    
    var DATE_DELIM = /[\x09\x20-\x2F\x3B-\x40\x5B-\x60\x7B-\x7E]/;
    
    var MONTH_TO_NUM = {
      jan:0, feb:1, mar:2, apr:3, may:4, jun:5,
      jul:6, aug:7, sep:8, oct:9, nov:10, dec:11
    };
    var NUM_TO_MONTH = [
      'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'
    ];
    var NUM_TO_DAY = [
      'Sun','Mon','Tue','Wed','Thu','Fri','Sat'
    ];
    
    var MAX_TIME = 2147483647000; // 31-bit max
    var MIN_TIME = 0; // 31-bit min
    
    /*
     * Parses a Natural number (i.e., non-negative integer) with either the
     *    <min>*<max>DIGIT ( non-digit *OCTET )
     * or
     *    <min>*<max>DIGIT
     * grammar (RFC6265 S5.1.1).
     *
     * The "trailingOK" boolean controls if the grammar accepts a
     * "( non-digit *OCTET )" trailer.
     */
    function parseDigits(token, minDigits, maxDigits, trailingOK) {
      var count = 0;
      while (count < token.length) {
        var c = token.charCodeAt(count);
        // "non-digit = %x00-2F / %x3A-FF"
        if (c <= 0x2F || c >= 0x3A) {
          break;
        }
        count++;
      }
    
      // constrain to a minimum and maximum number of digits.
      if (count < minDigits || count > maxDigits) {
        return null;
      }
    
      if (!trailingOK && count != token.length) {
        return null;
      }
    
      return parseInt(token.substr(0,count), 10);
    }
    
    function parseTime(token) {
      var parts = token.split(':');
      var result = [0,0,0];
    
      /* RF6256 S5.1.1:
       *      time            = hms-time ( non-digit *OCTET )
       *      hms-time        = time-field ":" time-field ":" time-field
       *      time-field      = 1*2DIGIT
       */
    
      if (parts.length !== 3) {
        return null;
      }
    
      for (var i = 0; i < 3; i++) {
        // "time-field" must be strictly "1*2DIGIT", HOWEVER, "hms-time" can be
        // followed by "( non-digit *OCTET )" so therefore the last time-field can
        // have a trailer
        var trailingOK = (i == 2);
        var num = parseDigits(parts[i], 1, 2, trailingOK);
        if (num === null) {
          return null;
        }
        result[i] = num;
      }
    
      return result;
    }
    
    function parseMonth(token) {
      token = String(token).substr(0,3).toLowerCase();
      var num = MONTH_TO_NUM[token];
      return num >= 0 ? num : null;
    }
    
    /*
     * RFC6265 S5.1.1 date parser (see RFC for full grammar)
     */
    function parseDate(str) {
      if (!str) {
        return;
      }
    
      /* RFC6265 S5.1.1:
       * 2. Process each date-token sequentially in the order the date-tokens
       * appear in the cookie-date
       */
      var tokens = str.split(DATE_DELIM);
      if (!tokens) {
        return;
      }
    
      var hour = null;
      var minute = null;
      var second = null;
      var dayOfMonth = null;
      var month = null;
      var year = null;
    
      for (var i=0; i<tokens.length; i++) {
        var token = tokens[i].trim();
        if (!token.length) {
          continue;
        }
    
        var result;
    
        /* 2.1. If the found-time flag is not set and the token matches the time
         * production, set the found-time flag and set the hour- value,
         * minute-value, and second-value to the numbers denoted by the digits in
         * the date-token, respectively.  Skip the remaining sub-steps and continue
         * to the next date-token.
         */
        if (second === null) {
          result = parseTime(token);
          if (result) {
            hour = result[0];
            minute = result[1];
            second = result[2];
            continue;
          }
        }
    
        /* 2.2. If the found-day-of-month flag is not set and the date-token matches
         * the day-of-month production, set the found-day-of- month flag and set
         * the day-of-month-value to the number denoted by the date-token.  Skip
         * the remaining sub-steps and continue to the next date-token.
         */
        if (dayOfMonth === null) {
          // "day-of-month = 1*2DIGIT ( non-digit *OCTET )"
          result = parseDigits(token, 1, 2, true);
          if (result !== null) {
            dayOfMonth = result;
            continue;
          }
        }
    
        /* 2.3. If the found-month flag is not set and the date-token matches the
         * month production, set the found-month flag and set the month-value to
         * the month denoted by the date-token.  Skip the remaining sub-steps and
         * continue to the next date-token.
         */
        if (month === null) {
          result = parseMonth(token);
          if (result !== null) {
            month = result;
            continue;
          }
        }
    
        /* 2.4. If the found-year flag is not set and the date-token matches the
         * year production, set the found-year flag and set the year-value to the
         * number denoted by the date-token.  Skip the remaining sub-steps and
         * continue to the next date-token.
         */
        if (year === null) {
          // "year = 2*4DIGIT ( non-digit *OCTET )"
          result = parseDigits(token, 2, 4, true);
          if (result !== null) {
            year = result;
            /* From S5.1.1:
             * 3.  If the year-value is greater than or equal to 70 and less
             * than or equal to 99, increment the year-value by 1900.
             * 4.  If the year-value is greater than or equal to 0 and less
             * than or equal to 69, increment the year-value by 2000.
             */
            if (year >= 70 && year <= 99) {
              year += 1900;
            } else if (year >= 0 && year <= 69) {
              year += 2000;
            }
          }
        }
      }
    
      /* RFC 6265 S5.1.1
       * "5. Abort these steps and fail to parse the cookie-date if:
       *     *  at least one of the found-day-of-month, found-month, found-
       *        year, or found-time flags is not set,
       *     *  the day-of-month-value is less than 1 or greater than 31,
       *     *  the year-value is less than 1601,
       *     *  the hour-value is greater than 23,
       *     *  the minute-value is greater than 59, or
       *     *  the second-value is greater than 59.
       *     (Note that leap seconds cannot be represented in this syntax.)"
       *
       * So, in order as above:
       */
      if (
        dayOfMonth === null || month === null || year === null || second === null ||
        dayOfMonth < 1 || dayOfMonth > 31 ||
        year < 1601 ||
        hour > 23 ||
        minute > 59 ||
        second > 59
      ) {
        return;
      }
    
      return new Date(Date.UTC(year, month, dayOfMonth, hour, minute, second));
    }
    
    function formatDate(date) {
      var d = date.getUTCDate(); d = d >= 10 ? d : '0'+d;
      var h = date.getUTCHours(); h = h >= 10 ? h : '0'+h;
      var m = date.getUTCMinutes(); m = m >= 10 ? m : '0'+m;
      var s = date.getUTCSeconds(); s = s >= 10 ? s : '0'+s;
      return NUM_TO_DAY[date.getUTCDay()] + ', ' +
        d+' '+ NUM_TO_MONTH[date.getUTCMonth()] +' '+ date.getUTCFullYear() +' '+
        h+':'+m+':'+s+' GMT';
    }
    
    // S5.1.2 Canonicalized Host Names
    function canonicalDomain(str) {
      if (str == null) {
        return null;
      }
      str = str.trim().replace(/^\./,''); // S4.1.2.3 & S5.2.3: ignore leading .
    
      // convert to IDN if any non-ASCII characters
      if (punycode && /[^\u0001-\u007f]/.test(str)) {
        str = punycode.toASCII(str);
      }
    
      return str.toLowerCase();
    }
    
    // S5.1.3 Domain Matching
    function domainMatch(str, domStr, canonicalize) {
      if (str == null || domStr == null) {
        return null;
      }
      if (canonicalize !== false) {
        str = canonicalDomain(str);
        domStr = canonicalDomain(domStr);
      }
    
      /*
       * "The domain string and the string are identical. (Note that both the
       * domain string and the string will have been canonicalized to lower case at
       * this point)"
       */
      if (str == domStr) {
        return true;
      }
    
      /* "All of the following [three] conditions hold:" (order adjusted from the RFC) */
    
      /* "* The string is a host name (i.e., not an IP address)." */
      if (net.isIP(str)) {
        return false;
      }
    
      /* "* The domain string is a suffix of the string" */
      var idx = str.indexOf(domStr);
      if (idx <= 0) {
        return false; // it's a non-match (-1) or prefix (0)
      }
    
      // e.g "a.b.c".indexOf("b.c") === 2
      // 5 === 3+2
      if (str.length !== domStr.length + idx) { // it's not a suffix
        return false;
      }
    
      /* "* The last character of the string that is not included in the domain
      * string is a %x2E (".") character." */
      if (str.substr(idx-1,1) !== '.') {
        return false;
      }
    
      return true;
    }
    
    
    // RFC6265 S5.1.4 Paths and Path-Match
    
    /*
     * "The user agent MUST use an algorithm equivalent to the following algorithm
     * to compute the default-path of a cookie:"
     *
     * Assumption: the path (and not query part or absolute uri) is passed in.
     */
    function defaultPath(path) {
      // "2. If the uri-path is empty or if the first character of the uri-path is not
      // a %x2F ("/") character, output %x2F ("/") and skip the remaining steps.
      if (!path || path.substr(0,1) !== "/") {
        return "/";
      }
    
      // "3. If the uri-path contains no more than one %x2F ("/") character, output
      // %x2F ("/") and skip the remaining step."
      if (path === "/") {
        return path;
      }
    
      var rightSlash = path.lastIndexOf("/");
      if (rightSlash === 0) {
        return "/";
      }
    
      // "4. Output the characters of the uri-path from the first character up to,
      // but not including, the right-most %x2F ("/")."
      return path.slice(0, rightSlash);
    }
    
    function trimTerminator(str) {
      for (var t = 0; t < TERMINATORS.length; t++) {
        var terminatorIdx = str.indexOf(TERMINATORS[t]);
        if (terminatorIdx !== -1) {
          str = str.substr(0,terminatorIdx);
        }
      }
    
      return str;
    }
    
    function parseCookiePair(cookiePair, looseMode) {
      cookiePair = trimTerminator(cookiePair);
    
      var firstEq = cookiePair.indexOf('=');
      if (looseMode) {
        if (firstEq === 0) { // '=' is immediately at start
          cookiePair = cookiePair.substr(1);
          firstEq = cookiePair.indexOf('='); // might still need to split on '='
        }
      } else { // non-loose mode
        if (firstEq <= 0) { // no '=' or is at start
          return; // needs to have non-empty "cookie-name"
        }
      }
    
      var cookieName, cookieValue;
      if (firstEq <= 0) {
        cookieName = "";
        cookieValue = cookiePair.trim();
      } else {
        cookieName = cookiePair.substr(0, firstEq).trim();
        cookieValue = cookiePair.substr(firstEq+1).trim();
      }
    
      if (CONTROL_CHARS.test(cookieName) || CONTROL_CHARS.test(cookieValue)) {
        return;
      }
    
      var c = new Cookie();
      c.key = cookieName;
      c.value = cookieValue;
      return c;
    }
    
    function parse(str, options) {
      if (!options || typeof options !== 'object') {
        options = {};
      }
      str = str.trim();
    
      // We use a regex to parse the "name-value-pair" part of S5.2
      var firstSemi = str.indexOf(';'); // S5.2 step 1
      var cookiePair = (firstSemi === -1) ? str : str.substr(0, firstSemi);
      var c = parseCookiePair(cookiePair, !!options.loose);
      if (!c) {
        return;
      }
    
      if (firstSemi === -1) {
        return c;
      }
    
      // S5.2.3 "unparsed-attributes consist of the remainder of the set-cookie-string
      // (including the %x3B (";") in question)." plus later on in the same section
      // "discard the first ";" and trim".
      var unparsed = str.slice(firstSemi + 1).trim();
    
      // "If the unparsed-attributes string is empty, skip the rest of these
      // steps."
      if (unparsed.length === 0) {
        return c;
      }
    
      /*
       * S5.2 says that when looping over the items "[p]rocess the attribute-name
       * and attribute-value according to the requirements in the following
       * subsections" for every item.  Plus, for many of the individual attributes
       * in S5.3 it says to use the "attribute-value of the last attribute in the
       * cookie-attribute-list".  Therefore, in this implementation, we overwrite
       * the previous value.
       */
      var cookie_avs = unparsed.split(';');
      while (cookie_avs.length) {
        var av = cookie_avs.shift().trim();
        if (av.length === 0) { // happens if ";;" appears
          continue;
        }
        var av_sep = av.indexOf('=');
        var av_key, av_value;
    
        if (av_sep === -1) {
          av_key = av;
          av_value = null;
        } else {
          av_key = av.substr(0,av_sep);
          av_value = av.substr(av_sep+1);
        }
    
        av_key = av_key.trim().toLowerCase();
    
        if (av_value) {
          av_value = av_value.trim();
        }
    
        switch(av_key) {
        case 'expires': // S5.2.1
          if (av_value) {
            var exp = parseDate(av_value);
            // "If the attribute-value failed to parse as a cookie date, ignore the
            // cookie-av."
            if (exp) {
              // over and underflow not realistically a concern: V8's getTime() seems to
              // store something larger than a 32-bit time_t (even with 32-bit node)
              c.expires = exp;
            }
          }
          break;
    
        case 'max-age': // S5.2.2
          if (av_value) {
            // "If the first character of the attribute-value is not a DIGIT or a "-"
            // character ...[or]... If the remainder of attribute-value contains a
            // non-DIGIT character, ignore the cookie-av."
            if (/^-?[0-9]+$/.test(av_value)) {
              var delta = parseInt(av_value, 10);
              // "If delta-seconds is less than or equal to zero (0), let expiry-time
              // be the earliest representable date and time."
              c.setMaxAge(delta);
            }
          }
          break;
    
        case 'domain': // S5.2.3
          // "If the attribute-value is empty, the behavior is undefined.  However,
          // the user agent SHOULD ignore the cookie-av entirely."
          if (av_value) {
            // S5.2.3 "Let cookie-domain be the attribute-value without the leading %x2E
            // (".") character."
            var domain = av_value.trim().replace(/^\./, '');
            if (domain) {
              // "Convert the cookie-domain to lower case."
              c.domain = domain.toLowerCase();
            }
          }
          break;
    
        case 'path': // S5.2.4
          /*
           * "If the attribute-value is empty or if the first character of the
           * attribute-value is not %x2F ("/"):
           *   Let cookie-path be the default-path.
           * Otherwise:
           *   Let cookie-path be the attribute-value."
           *
           * We'll represent the default-path as null since it depends on the
           * context of the parsing.
           */
          c.path = av_value && av_value[0] === "/" ? av_value : null;
          break;
    
        case 'secure': // S5.2.5
          /*
           * "If the attribute-name case-insensitively matches the string "Secure",
           * the user agent MUST append an attribute to the cookie-attribute-list
           * with an attribute-name of Secure and an empty attribute-value."
           */
          c.secure = true;
          break;
    
        case 'httponly': // S5.2.6 -- effectively the same as 'secure'
          c.httpOnly = true;
          break;
    
        default:
          c.extensions = c.extensions || [];
          c.extensions.push(av);
          break;
        }
      }
    
      return c;
    }
    
    // avoid the V8 deoptimization monster!
    function jsonParse(str) {
      var obj;
      try {
        obj = JSON.parse(str);
      } catch (e) {
        return e;
      }
      return obj;
    }
    
    function fromJSON(str) {
      if (!str) {
        return null;
      }
    
      var obj;
      if (typeof str === 'string') {
        obj = jsonParse(str);
        if (obj instanceof Error) {
          return null;
        }
      } else {
        // assume it's an Object
        obj = str;
      }
    
      var c = new Cookie();
      for (var i=0; i<Cookie.serializableProperties.length; i++) {
        var prop = Cookie.serializableProperties[i];
        if (obj[prop] === undefined ||
            obj[prop] === Cookie.prototype[prop])
        {
          continue; // leave as prototype default
        }
    
        if (prop === 'expires' ||
            prop === 'creation' ||
            prop === 'lastAccessed')
        {
          if (obj[prop] === null) {
            c[prop] = null;
          } else {
            c[prop] = obj[prop] == "Infinity" ?
              "Infinity" : new Date(obj[prop]);
          }
        } else {
          c[prop] = obj[prop];
        }
      }
    
      return c;
    }
    
    /* Section 5.4 part 2:
     * "*  Cookies with longer paths are listed before cookies with
     *     shorter paths.
     *
     *  *  Among cookies that have equal-length path fields, cookies with
     *     earlier creation-times are listed before cookies with later
     *     creation-times."
     */
    
    function cookieCompare(a,b) {
      var cmp = 0;
    
      // descending for length: b CMP a