tor-browser

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

textdecoder-labels.any.js (1382B)


      1 // META: title=Encoding API: Encoding labels
      2 // META: script=resources/encodings.js
      3 // META: timeout=long
      4 
      5 var whitespace = [' ', '\t', '\n', '\f', '\r'];
      6 encodings_table.forEach(function(section) {
      7  section.encodings.filter(function(encoding) {
      8    return encoding.name !== 'replacement';
      9  }).forEach(function(encoding) {
     10    encoding.labels.forEach(function(label) {
     11      const textDecoderName = encoding.name.toLowerCase(); // ASCII names only, so safe
     12      test(function(t) {
     13        assert_equals(
     14          new TextDecoder(label).encoding, textDecoderName,
     15          'label for encoding should match');
     16        assert_equals(
     17          new TextDecoder(label.toUpperCase()).encoding, textDecoderName,
     18          'label matching should be case-insensitive');
     19        whitespace.forEach(function(ws) {
     20          assert_equals(
     21            new TextDecoder(ws + label).encoding, textDecoderName,
     22            'label for encoding with leading whitespace should match');
     23          assert_equals(
     24            new TextDecoder(label + ws).encoding, textDecoderName,
     25            'label for encoding with trailing whitespace should match');
     26          assert_equals(
     27            new TextDecoder(ws + label + ws).encoding, textDecoderName,
     28            'label for encoding with surrounding whitespace should match');
     29        });
     30      }, label + ' => ' + encoding.name);
     31    });
     32  });
     33 });