[tor-commits] [flashproxy/master] Copy parse_cookie_string to options.html.

dcf at torproject.org dcf at torproject.org
Fri Dec 28 14:13:54 UTC 2012


commit 451912bfcfe591d389b13cadb70851d3fb09c788
Author: David Fifield <david at bamsoftware.com>
Date:   Tue Dec 25 12:11:55 2012 -0800

    Copy parse_cookie_string to options.html.
---
 proxy/options.html |   41 ++++++++++++++++++++++++++++-------------
 1 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/proxy/options.html b/proxy/options.html
index 59f0125..b7e8c59 100644
--- a/proxy/options.html
+++ b/proxy/options.html
@@ -81,23 +81,38 @@ function set_cookie_disallowed() {
     document.cookie = COOKIE_NAME + "=0 ;path=/ ;expires=" + COOKIE_LIFETIME;
 }
 
-/* Returns the value of the cookie, or undefined
-   if the cookie is not present. */
-function read_cookie() {
-    var str, j;
-    var cookies = document.cookie.split(";");
+function parse_cookie_string(cookies) {
+    var strings;
+    var result;
 
-    for (i in cookies) {
-        str = cookies[i];
+    result = {};
+    if (cookies)
+        strings = cookies.split(";");
+    else
+        strings = [];
+    for (var i = 0; i < strings.length; i++) {
+        var string = strings[i];
+        var j, name, value;
 
-        while (str[0] === " ")
-            str = str.substr(1);
+        j = string.indexOf("=");
+        if (j === -1) {
+            return null;
+        }
+        name = decodeURIComponent(string.substr(0, j).trim());
+        value = decodeURIComponent(string.substr(j + 1).trim());
 
-        j = str.indexOf("=");
-        if (COOKIE_NAME === str.substr(0, j))
-            return str.substr(j + 1);
+        if (!(name in result))
+             result[name] = value;
     }
-    return undefined;
+
+    return result;
+}
+
+/* Returns the value of the cookie, or undefined
+   if the cookie is not present. */
+function read_cookie() {
+    var cookies = parse_cookie_string(document.cookie);
+    return cookies[COOKIE_NAME];
 }
 
 /* Updates the text telling the user what his current setting is.*/





More information about the tor-commits mailing list