~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/media/common/util.js

  • Committer: mattgiuca
  • Date: 2008-01-11 02:50:10 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:174
util: Fixed up URL encoding; documented properly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
 * whose names appear multiple times.
98
98
 * args is never null, though it may be empty.
99
99
 *
100
 
 * The args strings are decoded from URL encoding form. Other strings are left
101
 
 * in raw URL form.
 
100
 * All strings are decoded/unescaped. Reserved characters
 
101
 * (; , / ? : @ & = + * $) are not decoded except in args.
102
102
 *
103
103
 * \param url String. A URL. To read from the current browser window, use
104
104
 *  window.location.href.
111
111
    var serverpart;
112
112
    var args;
113
113
 
 
114
    url = decodeURI(url);
 
115
 
114
116
    /* Split scheme from rest */
115
117
    index = url.indexOf("://");
116
118
    if (index < 0)
182
184
            /* Ignore malformed args */
183
185
            if (index >= 0)
184
186
            {
185
 
                arg_key = decodeURI(arg_str.substr(0, index));
186
 
                arg_val = decodeURI(arg_str.substr(index+1));
 
187
                arg_key = decodeURIComponent(arg_str.substr(0, index));
 
188
                arg_val = decodeURIComponent(arg_str.substr(index+1));
187
189
                if (arg_key in args)
188
190
                {
189
191
                    /* Collision - make an array */
203
205
}
204
206
 
205
207
/** Given an object exactly of the form described for the output of parseurl,
206
 
 * returns a URL string built from those parameters.
 
208
 * returns a URL string built from those parameters. The URL is properly
 
209
 * encoded.
207
210
 * parseurl and buildurl are strict inverses of each other.
208
211
 * Note that either query_string or args may be supplied. If both are
209
212
 * supplied, query_string is preferred (because it keeps the argument order).
241
244
            arg_val = obj.args[arg_key];
242
245
            if (arg_val instanceof Array)
243
246
                for (var i=0; i<arg_val.length; i++)
244
 
                    query_string += "&" + encodeURI(arg_key) + "=" +
245
 
                        encodeURI(arg_val[i]);
 
247
                    query_string += "&" + encodeURIComponent(arg_key) + "=" +
 
248
                        encodeURIComponent(arg_val[i]);
246
249
            else
247
 
                query_string += "&" + encodeURI(arg_key) + "=" +
248
 
                    encodeURI(arg_val);
 
250
                query_string += "&" + encodeURIComponent(arg_key) + "=" +
 
251
                    encodeURIComponent(arg_val);
249
252
        }
250
253
        if (query_string == "")
251
254
            query_string = null;
257
260
    if (query_string != null)
258
261
        url += "?" + query_string;
259
262
 
260
 
    return url;
 
263
    return encodeURI(url);
261
264
}
262
265
 
263
266
/** Given an argument map, as output in the args parameter of the return of