~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-14 05:54:31 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:225
util.js: Yet more fixes for encoding/decoding URIs. build_url and parse_url
    had some instances of multiple encoding/decoding. Now confident they will
    correctly encode/decode just once.
browser.js: Combined settitle and presentpath (since they have very related
    actions, the one function just does both).

Show diffs side-by-side

added added

removed removed

Lines of Context:
149
149
 * args is never null, though it may be empty.
150
150
 *
151
151
 * All strings are decoded/unescaped. Reserved characters
152
 
 * (; , / ? : @ & = + * $) are not decoded except in args.
 
152
 * (; , / ? : @ & = + * $) are not decoded except in args and path.
153
153
 *
154
154
 * \param url String. A URL. To read from the current browser window, use
155
155
 *  window.location.href.
162
162
    var serverpart;
163
163
    var args;
164
164
 
165
 
    url = decodeURI(url);
166
 
 
167
165
    /* Split scheme from rest */
168
166
    index = url.indexOf("://");
169
167
    if (index < 0)
220
218
            obj.query_string = url.substr(index+1);
221
219
        }
222
220
    }
 
221
    obj.path = decodeURIComponent(obj.path);
223
222
 
224
223
    /* Split query string into arguments */
225
224
    args = {};
307
306
        url += ":" + obj.server_port.toString();
308
307
    if (("path" in obj) && obj.path != null)
309
308
    {
310
 
        var path = obj.path.toString();
 
309
        var path = urlencode_path(obj.path.toString());
311
310
        if (url.length > 0 && path.length > 0 && path[0] != "/")
312
311
            path = "/" + path;
313
312
        url += path;
314
313
    }
315
314
    if (("query_string" in obj) && obj.query_string != null)
316
 
        query_string = obj.query_string.toString();
 
315
        query_string = encodeURI(obj.query_string.toString());
317
316
    else if (("args" in obj) && obj.args != null)
318
317
        query_string = make_query_string(obj.args);
319
318
 
320
319
    if (query_string != null)
321
320
        url += "?" + query_string;
322
321
 
323
 
    return encodeURI(url);
 
322
    return url;
324
323
}
325
324
 
326
325
/** URL-encodes a path. This is a special case of URL encoding as all
519
518
{
520
519
    if (content_type != "multipart/form-data")
521
520
        content_type = "application/x-www-form-urlencoded";
522
 
    path = urlencode_path(app_path(app, path));
 
521
    path = app_path(app, path);
523
522
    var url;
524
523
    /* A random string, for multipart/form-data
525
524
     * (This is not checked against anywhere else, it is solely defined and