Ticket #9069: 0001-Test-if-userAgent-is-a-string.patch

File 0001-Test-if-userAgent-is-a-string.patch, 3.2 KB (added by arlolra, 5 years ago)
  • proxy/flashproxy-test.js

    From 1565e98df4930f3972a6b441bc631f7cc05d8bb3 Mon Sep 17 00:00:00 2001
    From: Arlo Breault <arlolra@gmail.com>
    Date: Wed, 6 Nov 2013 14:50:51 -0800
    Subject: [PATCH] Test if userAgent is a string.
    
    Removes ambiguity and fixes a potential crash in
    flashproxy_should_disable().
    ---
     proxy/flashproxy-test.js | 16 ++++++++++++++++
     proxy/flashproxy.js      | 23 ++++++++++++++---------
     2 files changed, 30 insertions(+), 9 deletions(-)
    
    diff --git a/proxy/flashproxy-test.js b/proxy/flashproxy-test.js
    index 976fd44..8ab5784 100755
    a b function test_have_websocket_binary_frames() { 
    344344    window.navigator = _navigator;
    345345}
    346346
     347function test_is_string() {
     348    var TESTS = [
     349        { variable: "this is a string", expected: true },
     350        { variable: new String("this is another string"), expected: true },
     351        { variable: new Object(), expected: false },
     352        { variable: 12345, expected: false },
     353    ];
     354    for (var i = 0; i < TESTS.length; i++) {
     355        var test = TESTS[i];
     356        var actual = is_string(test.variable);
     357        if (actual !== test.expected)
     358            fail(test.variable, test.expected, actual)
     359    }
     360}
     361
    347362test_build_url();
    348363test_parse_cookie_string();
    349364test_parse_query_string();
    test_parse_addr_spec(); 
    352367test_get_param_addr();
    353368test_lang_keys();
    354369test_have_websocket_binary_frames();
     370test_is_string();
    355371
    356372if (num_failed == 0)
    357373    quit(0);
  • proxy/flashproxy.js

    diff --git a/proxy/flashproxy.js b/proxy/flashproxy.js
    index 7a9e75d..cb3c92a 100644
    a b function puts(s) { 
    119119    }
    120120}
    121121
     122/* Helper to test if a variable is a string */
     123function is_string(o) {
     124    return typeof o === "string" || (typeof o === "object" && o.constructor === String);
     125}
     126
    122127/* Parse a cookie data string (usually document.cookie). The return type
    123128   is an object mapping cookies names to values. Returns null on error.
    124129
    function have_websocket_binary_frames() { 
    429434    var ua, matches, browsers, reg;
    430435
    431436    ua = window.navigator.userAgent;
    432     if (ua == null)
     437    if (!is_string(ua))
    433438        return false;
    434439
    435440    browsers = [
    function flashproxy_should_disable() { 
    10551060    }
    10561061
    10571062    ua = window.navigator.userAgent;
    1058     if (ua !== null) {
     1063    if (is_string(ua)) {
    10591064        var UA_LIST = [
    10601065            /\bmobile\b/i,
    10611066            /\bandroid\b/i,
    function flashproxy_should_disable() { 
    10701075                return true;
    10711076            }
    10721077        }
    1073     }
    10741078
    1075     if (ua.match(/\bsafari\b/i) && !ua.match(/\bchrome\b/i)
    1076         && !ua.match(/\bversion\/[6789]\./i)) {
    1077         /* Disable before Safari 6.0 because it doesn't have the hybi/RFC type
    1078            of WebSockets. */
    1079         puts("Disable because User-Agent is Safari before 6.0.");
    1080         return true;
     1079        if (ua.match(/\bsafari\b/i) && !ua.match(/\bchrome\b/i)
     1080            && !ua.match(/\bversion\/[6789]\./i)) {
     1081            /* Disable before Safari 6.0 because it doesn't have the hybi/RFC
     1082               type of WebSockets. */
     1083            puts("Disable because User-Agent is Safari before 6.0.");
     1084            return true;
     1085        }
    10811086    }
    10821087
    10831088    if (!WebSocket) {