tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

html-extensions.js (3762B)


      1 var noParamFuns = ["".bold, "".italics, "".fixed, "".strike, "".small, "".big,
      2            "".blink, "".sup, "".sub];
      3 var noParamTags = ["b", "i", "tt", "strike", "small", "big",
      4 	   "blink", "sup", "sub"];
      5 
      6 function testNoParam(s) {
      7    for (var i=0; i<noParamFuns.length; i++) {
      8 var fun = noParamFuns[i];
      9 assertEq(fun.length, 0);
     10 var res = fun.call(s);
     11 var tag = noParamTags[i];
     12 assertEq(res, "<" + tag + ">" + String(s) + "</" + tag + ">");
     13    }
     14 }
     15 testNoParam("Foo");
     16 testNoParam('aaa"bbb\'c<>123');
     17 testNoParam(123);
     18 
     19 // toString should be called, not valueOf
     20 testNoParam({toString: () => 1, valueOf: () => { throw "fail"; } });
     21 
     22 assertEq("".anchor.length, 1);
     23 assertEq("".link.length, 1);
     24 assertEq("".fontsize.length, 1);
     25 assertEq("".fontcolor.length, 1);
     26 
     27 // Ensure @@replace on String.prototype isn't called.
     28 String.prototype[Symbol.replace] = function() {
     29    throw "Shouldn't call @@replace";
     30 };
     31 
     32 // " in the attribute value is escaped (&quot;)
     33 assertEq("bla\"<>'".anchor("foo'<>\"\"123\"/\\"),
     34  "<a name=\"foo'<>&quot;&quot;123&quot;/\\\">bla\"<>'</a>");
     35 assertEq("bla\"<>'".link("foo'<>\"\"123\"/\\"),
     36  "<a href=\"foo'<>&quot;&quot;123&quot;/\\\">bla\"<>'</a>");
     37 assertEq("bla\"<>'".fontsize("foo'<>\"\"123\"/\\"),
     38  "<font size=\"foo'<>&quot;&quot;123&quot;/\\\">bla\"<>'</font>");
     39 assertEq("bla\"<>'".fontcolor("foo'<>\"\"123\"/\\"),
     40  "<font color=\"foo'<>&quot;&quot;123&quot;/\\\">bla\"<>'</font>");
     41 
     42 assertEq("".anchor('"'), '<a name="&quot;"></a>');
     43 assertEq("".link('"'), '<a href="&quot;"></a>');
     44 assertEq("".fontcolor('"'), '<font color="&quot;"></font>');
     45 assertEq("".fontsize('"'), '<font size="&quot;"></font>');
     46 
     47 assertEq("".anchor('"1'), '<a name="&quot;1"></a>');
     48 assertEq("".link('"1'), '<a href="&quot;1"></a>');
     49 assertEq("".fontcolor('"1'), '<font color="&quot;1"></font>');
     50 assertEq("".fontsize('"1'), '<font size="&quot;1"></font>');
     51 
     52 assertEq("".anchor('"""a"'), '<a name="&quot;&quot;&quot;a&quot;"></a>');
     53 assertEq("".link('"""a"'), '<a href="&quot;&quot;&quot;a&quot;"></a>');
     54 assertEq("".fontcolor('"""a"'), '<font color="&quot;&quot;&quot;a&quot;"></font>');
     55 assertEq("".fontsize('"""a"'), '<font size="&quot;&quot;&quot;a&quot;"></font>');
     56 
     57 assertEq("".anchor(""), '<a name=""></a>');
     58 assertEq("".link(""), '<a href=""></a>');
     59 assertEq("".fontcolor(""), '<font color=""></font>');
     60 assertEq("".fontsize(""), '<font size=""></font>');
     61 
     62 assertEq("foo".anchor(), "<a name=\"undefined\">foo</a>");
     63 assertEq("foo".link(), "<a href=\"undefined\">foo</a>");
     64 assertEq("foo".fontcolor(), "<font color=\"undefined\">foo</font>");
     65 assertEq("foo".fontsize(), "<font size=\"undefined\">foo</font>");
     66 
     67 assertEq("foo".anchor(3.14), '<a name="3.14">foo</a>');
     68 assertEq("foo".link(3.14), '<a href="3.14">foo</a>');
     69 assertEq("foo".fontcolor(3.14), '<font color="3.14">foo</font>');
     70 assertEq("foo".fontsize(3.14), '<font size="3.14">foo</font>');
     71 
     72 assertEq("foo".anchor({}), '<a name="[object Object]">foo</a>');
     73 assertEq("foo".link(Math), '<a href="[object Math]">foo</a>');
     74 assertEq("foo".fontcolor([1,2]), '<font color="1,2">foo</font>');
     75 assertEq("foo".fontsize({}), '<font size="[object Object]">foo</font>');
     76 
     77 // toString should be called, not valueOf, and toString must be called on |this|
     78 // before it's called on the argument. Also makes sure toString is called only
     79 // once.
     80 var count = 0;
     81 var o1 = {toString: () => { return count += 1; }, valueOf: () => { throw "fail"; } };
     82 var o2 = {toString: () => { return count += 5; }, valueOf: () => { throw "fail"; } };
     83 assertEq("".anchor.call(o1, o2), '<a name="6">1</a>');
     84 assertEq("".link.call(o1, o2), '<a href="12">7</a>');
     85 assertEq("".fontcolor.call(o1, o2), '<font color="18">13</font>');
     86 assertEq("".fontsize.call(o1, o2), '<font size="24">19</font>');
     87 assertEq(count, 24);