1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-21 15:48:06 +02:00

Add // prettier-ignore comments to prevent re-formatting of certain data structures

There's a fair number of (primarily) `Array`s/`TypedArray`s whose formatting we don't want disturb, since in many cases that would lead to the code becoming much more difficult to read and/or break existing inline comments.

*Please note:* It may be a good idea to look through these cases individually, and possibly re-write some of the them (especially the `String` ones) to reduce the need for all of these ignore commands.
This commit is contained in:
Jonas Jenwald 2019-12-25 15:54:34 +01:00
parent c3a1c67950
commit 8ec1dfde49
25 changed files with 130 additions and 3 deletions

View file

@ -120,6 +120,7 @@ describe('CFFParser', function() {
it('ignores reserved commands in parseDict, and refuses to add privateDict ' +
'keys with invalid values (bug 1308536)', function () {
// prettier-ignore
var bytes = new Uint8Array([
64, 39, 31, 30, 252, 114, 137, 115, 79, 30, 197, 119, 2, 99, 127, 6
]);
@ -137,6 +138,7 @@ describe('CFFParser', function() {
});
it('parses a CharString having cntrmask', function() {
// prettier-ignore
var bytes = new Uint8Array([0, 1, // count
1, // offsetSize
0, // offset[0]
@ -167,6 +169,7 @@ describe('CFFParser', function() {
/* seacAnalysisEnabled = */ true);
parser.parse(); // cff
// prettier-ignore
var bytes = new Uint8Array([0, 1, // count
1, // offsetSize
0, // offset[0]
@ -192,6 +195,7 @@ describe('CFFParser', function() {
/* seacAnalysisEnabled = */ false);
parser.parse(); // cff
// prettier-ignore
var bytes = new Uint8Array([0, 1, // count
1, // offsetSize
0, // offset[0]
@ -208,6 +212,7 @@ describe('CFFParser', function() {
});
it('parses a CharString endchar no args', function() {
// prettier-ignore
var bytes = new Uint8Array([0, 1, // count
1, // offsetSize
0, // offset[0]
@ -230,6 +235,7 @@ describe('CFFParser', function() {
it('parses charset format 0', function() {
// The first three bytes make the offset large enough to skip predefined.
// prettier-ignore
var bytes = new Uint8Array([0x00, 0x00, 0x00,
0x00, // format
0x00, 0x02 // sid/cid
@ -245,6 +251,7 @@ describe('CFFParser', function() {
it('parses charset format 1', function() {
// The first three bytes make the offset large enough to skip predefined.
// prettier-ignore
var bytes = new Uint8Array([0x00, 0x00, 0x00,
0x01, // format
0x00, 0x08, // sid/cid start
@ -262,6 +269,7 @@ describe('CFFParser', function() {
it('parses charset format 2', function() {
// format 2 is the same as format 1 but the left is card16
// The first three bytes make the offset large enough to skip predefined.
// prettier-ignore
var bytes = new Uint8Array([0x00, 0x00, 0x00,
0x02, // format
0x00, 0x08, // sid/cid start
@ -278,6 +286,7 @@ describe('CFFParser', function() {
it('parses encoding format 0', function() {
// The first two bytes make the offset large enough to skip predefined.
// prettier-ignore
var bytes = new Uint8Array([0x00, 0x00,
0x00, // format
0x01, // count
@ -290,6 +299,7 @@ describe('CFFParser', function() {
it('parses encoding format 1', function() {
// The first two bytes make the offset large enough to skip predefined.
// prettier-ignore
var bytes = new Uint8Array([0x00, 0x00,
0x01, // format
0x01, // num ranges
@ -303,6 +313,7 @@ describe('CFFParser', function() {
});
it('parses fdselect format 0', function() {
// prettier-ignore
var bytes = new Uint8Array([0x00, // format
0x00, // gid: 0 fd: 0
0x01 // gid: 1 fd: 1
@ -315,6 +326,7 @@ describe('CFFParser', function() {
});
it('parses fdselect format 3', function() {
// prettier-ignore
var bytes = new Uint8Array([0x03, // format
0x00, 0x02, // range count
0x00, 0x00, // first gid
@ -331,6 +343,7 @@ describe('CFFParser', function() {
});
it('parses invalid fdselect format 3 (bug 1146106)', function() {
// prettier-ignore
var bytes = new Uint8Array([0x03, // format
0x00, 0x02, // range count
0x00, 0x01, // first gid (invalid)

View file

@ -57,6 +57,7 @@ describe('cmap', function() {
});
it('parses beginbfchar', function(done) {
// prettier-ignore
var str = '2 beginbfchar\n' +
'<03> <00>\n' +
'<04> <01>\n' +
@ -73,6 +74,7 @@ describe('cmap', function() {
});
});
it('parses beginbfrange with range', function(done) {
// prettier-ignore
var str = '1 beginbfrange\n' +
'<06> <0B> 0\n' +
'endbfrange\n';
@ -89,6 +91,7 @@ describe('cmap', function() {
});
});
it('parses beginbfrange with array', function(done) {
// prettier-ignore
var str = '1 beginbfrange\n' +
'<0D> <12> [ 0 1 2 3 4 5 ]\n' +
'endbfrange\n';
@ -105,6 +108,7 @@ describe('cmap', function() {
});
});
it('parses begincidchar', function(done) {
// prettier-ignore
var str = '1 begincidchar\n' +
'<14> 0\n' +
'endcidchar\n';
@ -119,6 +123,7 @@ describe('cmap', function() {
});
});
it('parses begincidrange', function(done) {
// prettier-ignore
var str = '1 begincidrange\n' +
'<0016> <001B> 0\n' +
'endcidrange\n';
@ -135,6 +140,7 @@ describe('cmap', function() {
});
});
it('decodes codespace ranges', function(done) {
// prettier-ignore
var str = '1 begincodespacerange\n' +
'<01> <02>\n' +
'<00000003> <00000004>\n' +
@ -155,6 +161,7 @@ describe('cmap', function() {
});
});
it('decodes 4 byte codespace ranges', function(done) {
// prettier-ignore
var str = '1 begincodespacerange\n' +
'<8EA1A1A1> <8EA1FEFE>\n' +
'endcodespacerange\n';

View file

@ -62,6 +62,7 @@ describe('colorspace', function () {
let testSrc = new Uint8Array([27, 125, 250, 131]);
let testDest = new Uint8ClampedArray(4 * 4 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
27, 27, 27,
27, 27, 27,
@ -103,6 +104,7 @@ describe('colorspace', function () {
let testSrc = new Uint8Array([27, 125, 250, 131]);
let testDest = new Uint8ClampedArray(3 * 3 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
27, 27, 27,
27, 27, 27,
@ -138,6 +140,7 @@ describe('colorspace', function () {
});
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
// prettier-ignore
let testSrc = new Uint8Array([
27, 125, 250,
131, 139, 140,
@ -145,6 +148,7 @@ describe('colorspace', function () {
21, 147, 255
]);
let testDest = new Uint8ClampedArray(4 * 4 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
27, 125, 250,
27, 125, 250,
@ -184,6 +188,7 @@ describe('colorspace', function () {
});
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
// prettier-ignore
let testSrc = new Uint8Array([
27, 125, 250,
131, 139, 140,
@ -191,6 +196,7 @@ describe('colorspace', function () {
21, 147, 255
]);
let testDest = new Uint8ClampedArray(3 * 3 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
27, 125, 250,
27, 125, 250,
@ -226,6 +232,7 @@ describe('colorspace', function () {
});
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
// prettier-ignore
let testSrc = new Uint8Array([
27, 125, 250, 128,
131, 139, 140, 45,
@ -233,6 +240,7 @@ describe('colorspace', function () {
21, 147, 255, 69
]);
let testDest = new Uint8ClampedArray(4 * 4 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
135, 81, 18,
135, 81, 18,
@ -272,6 +280,7 @@ describe('colorspace', function () {
});
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
// prettier-ignore
let testSrc = new Uint8Array([
27, 125, 250, 128,
131, 139, 140, 45,
@ -279,6 +288,7 @@ describe('colorspace', function () {
21, 147, 255, 69
]);
let testDest = new Uint8ClampedArray(3 * 3 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
135, 81, 18,
135, 81, 18,
@ -324,6 +334,7 @@ describe('colorspace', function () {
let testSrc = new Uint8Array([27, 125, 250, 131]);
let testDest = new Uint8ClampedArray(4 * 4 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
25, 25, 25,
25, 25, 25,
@ -375,6 +386,7 @@ describe('colorspace', function () {
});
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
// prettier-ignore
let testSrc = new Uint8Array([
27, 125, 250,
131, 139, 140,
@ -382,6 +394,7 @@ describe('colorspace', function () {
21, 147, 255
]);
let testDest = new Uint8ClampedArray(3 * 3 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
0, 238, 255,
0, 238, 255,
@ -425,6 +438,7 @@ describe('colorspace', function () {
});
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
// prettier-ignore
let testSrc = new Uint8Array([
27, 25, 50,
31, 19, 40,
@ -432,6 +446,7 @@ describe('colorspace', function () {
21, 47, 55
]);
let testDest = new Uint8ClampedArray(3 * 3 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
0, 49, 101,
0, 49, 101,
@ -456,6 +471,7 @@ describe('colorspace', function () {
describe('IndexedCS', function () {
it('should handle the case when cs is an array', function () {
// prettier-ignore
let lookup = new Uint8Array([
23, 155, 35,
147, 69, 93,
@ -480,6 +496,7 @@ describe('colorspace', function () {
let testSrc = new Uint8Array([2, 2, 0, 1]);
let testDest = new Uint8ClampedArray(3 * 3 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
255, 109, 70,
255, 109, 70,
@ -536,6 +553,7 @@ describe('colorspace', function () {
let testSrc = new Uint8Array([27, 25, 50, 31]);
let testDest = new Uint8ClampedArray(3 * 3 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
226, 242, 241,
226, 242, 241,

View file

@ -334,6 +334,7 @@ describe('crypto', function() {
alg = new PDF17();
password = new Uint8Array([117, 115, 101, 114]);
userValidation = new Uint8Array([117, 169, 4, 32, 159, 101, 22, 220]);
// prettier-ignore
userPassword = new Uint8Array([131, 242, 143, 160, 87, 2, 138, 134, 79,
253, 189, 173, 224, 73, 144, 241, 190, 81,
197, 15, 249, 105, 145, 151, 15, 194, 65,
@ -347,10 +348,12 @@ describe('crypto', function() {
alg = new PDF17();
password = new Uint8Array([111, 119, 110, 101, 114]);
ownerValidation = new Uint8Array([243, 118, 71, 153, 128, 17, 101, 62]);
// prettier-ignore
ownerPassword = new Uint8Array([60, 98, 137, 35, 51, 101, 200, 152, 210,
178, 226, 228, 134, 205, 163, 24, 204,
126, 177, 36, 106, 50, 36, 125, 210, 172,
171, 120, 222, 108, 139, 115]);
// prettier-ignore
uBytes = new Uint8Array([131, 242, 143, 160, 87, 2, 138, 134, 79, 253,
189, 173, 224, 73, 144, 241, 190, 81, 197, 15,
249, 105, 145, 151, 15, 194, 65, 3, 1, 126, 187,
@ -366,11 +369,13 @@ describe('crypto', function() {
alg = new PDF17();
password = new Uint8Array([117, 115, 101, 114]);
userKeySalt = new Uint8Array([168, 94, 215, 192, 100, 38, 188, 40]);
// prettier-ignore
userEncryption = new Uint8Array([35, 150, 195, 169, 245, 51, 51, 255,
158, 158, 33, 242, 231, 75, 125, 190,
25, 126, 172, 114, 195, 244, 137, 245,
234, 165, 42, 74, 60, 38, 17, 17]);
result = alg.getUserKey(password, userKeySalt, userEncryption);
// prettier-ignore
expected = new Uint8Array([63, 114, 136, 209, 87, 61, 12, 30, 249, 1,
186, 144, 254, 248, 163, 153, 151, 51, 133,
10, 80, 152, 206, 15, 72, 187, 231, 33, 224,
@ -384,16 +389,19 @@ describe('crypto', function() {
alg = new PDF17();
password = new Uint8Array([111, 119, 110, 101, 114]);
ownerKeySalt = new Uint8Array([200, 245, 242, 12, 218, 123, 24, 120]);
// prettier-ignore
ownerEncryption = new Uint8Array([213, 202, 14, 189, 110, 76, 70, 191, 6,
195, 10, 190, 157, 100, 144, 85, 8, 62,
123, 178, 156, 229, 50, 40, 229, 216,
54, 222, 34, 38, 106, 223]);
// prettier-ignore
uBytes = new Uint8Array([131, 242, 143, 160, 87, 2, 138, 134, 79, 253,
189, 173, 224, 73, 144, 241, 190, 81, 197, 15,
249, 105, 145, 151, 15, 194, 65, 3, 1, 126, 187,
221, 117, 169, 4, 32, 159, 101, 22, 220, 168,
94, 215, 192, 100, 38, 188, 40]);
result = alg.getOwnerKey(password, ownerKeySalt, uBytes, ownerEncryption);
// prettier-ignore
expected = new Uint8Array([63, 114, 136, 209, 87, 61, 12, 30, 249, 1,
186, 144, 254, 248, 163, 153, 151, 51, 133,
10, 80, 152, 206, 15, 72, 187, 231, 33, 224,
@ -408,6 +416,7 @@ describe('crypto', function() {
alg = new PDF20();
password = new Uint8Array([117, 115, 101, 114]);
userValidation = new Uint8Array([83, 245, 146, 101, 198, 247, 34, 198]);
// prettier-ignore
userPassword = new Uint8Array([94, 230, 205, 75, 166, 99, 250, 76, 219,
128, 17, 85, 57, 17, 33, 164, 150, 46,
103, 176, 160, 156, 187, 233, 166, 223,
@ -421,10 +430,12 @@ describe('crypto', function() {
alg = new PDF20();
password = new Uint8Array([111, 119, 110, 101, 114]);
ownerValidation = new Uint8Array([142, 232, 169, 208, 202, 214, 5, 185]);
// prettier-ignore
ownerPassword = new Uint8Array([88, 232, 62, 54, 245, 26, 245, 209, 137,
123, 221, 72, 199, 49, 37, 217, 31, 74,
115, 167, 127, 158, 176, 77, 45, 163, 87,
47, 39, 90, 217, 141]);
// prettier-ignore
uBytes = new Uint8Array([94, 230, 205, 75, 166, 99, 250, 76, 219, 128,
17, 85, 57, 17, 33, 164, 150, 46, 103, 176, 160,
156, 187, 233, 166, 223, 163, 253, 147, 235, 95,
@ -440,11 +451,13 @@ describe('crypto', function() {
alg = new PDF20();
password = new Uint8Array([117, 115, 101, 114]);
userKeySalt = new Uint8Array([191, 11, 16, 94, 237, 216, 20, 175]);
// prettier-ignore
userEncryption = new Uint8Array([121, 208, 2, 181, 230, 89, 156, 60, 253,
143, 212, 28, 84, 180, 196, 177, 173,
128, 221, 107, 46, 20, 94, 186, 135, 51,
95, 24, 20, 223, 254, 36]);
result = alg.getUserKey(password, userKeySalt, userEncryption);
// prettier-ignore
expected = new Uint8Array([42, 218, 213, 39, 73, 91, 72, 79, 67, 38, 248,
133, 18, 189, 61, 34, 107, 79, 29, 56, 59,
181, 213, 118, 113, 34, 65, 210, 87, 174, 22,
@ -458,16 +471,19 @@ describe('crypto', function() {
alg = new PDF20();
password = new Uint8Array([111, 119, 110, 101, 114]);
ownerKeySalt = new Uint8Array([29, 208, 185, 46, 11, 76, 135, 149]);
// prettier-ignore
ownerEncryption = new Uint8Array([209, 73, 224, 77, 103, 155, 201, 181,
190, 68, 223, 20, 62, 90, 56, 210, 5,
240, 178, 128, 238, 124, 68, 254, 253,
244, 62, 108, 208, 135, 10, 251]);
// prettier-ignore
uBytes = new Uint8Array([94, 230, 205, 75, 166, 99, 250, 76, 219, 128,
17, 85, 57, 17, 33, 164, 150, 46, 103, 176, 160,
156, 187, 233, 166, 223, 163, 253, 147, 235, 95,
184, 83, 245, 146, 101, 198, 247, 34, 198, 191,
11, 16, 94, 237, 216, 20, 175]);
result = alg.getOwnerKey(password, ownerKeySalt, uBytes, ownerEncryption);
// prettier-ignore
expected = new Uint8Array([42, 218, 213, 39, 73, 91, 72, 79, 67, 38, 248,
133, 18, 189, 61, 34, 107, 79, 29, 56, 59,
181, 213, 118, 113, 34, 65, 210, 87, 174, 22,

View file

@ -214,6 +214,7 @@ describe('parser', function() {
describe('Linearization', function() {
it('should not find a linearization dictionary', function() {
// Not an actual linearization dictionary.
// prettier-ignore
const stream1 = new StringStream(
'3 0 obj\n' +
'<<\n' +
@ -225,6 +226,7 @@ describe('parser', function() {
expect(Linearization.create(stream1)).toEqual(null);
// Linearization dictionary with invalid version number.
// prettier-ignore
const stream2 = new StringStream(
'1 0 obj\n' +
'<<\n' +
@ -236,6 +238,7 @@ describe('parser', function() {
});
it('should accept a valid linearization dictionary', function() {
// prettier-ignore
const stream = new StringStream(
'131 0 obj\n' +
'<<\n' +
@ -264,6 +267,7 @@ describe('parser', function() {
it('should reject a linearization dictionary with invalid ' +
'integer parameters', function() {
// The /L parameter should be equal to the stream length.
// prettier-ignore
const stream1 = new StringStream(
'1 0 obj\n' +
'<<\n' +
@ -283,6 +287,7 @@ describe('parser', function() {
'dictionary does not equal the stream length.'));
// The /E parameter should not be zero.
// prettier-ignore
const stream2 = new StringStream(
'1 0 obj\n' +
'<<\n' +
@ -302,6 +307,7 @@ describe('parser', function() {
'dictionary is invalid.'));
// The /O parameter should be an integer.
// prettier-ignore
const stream3 = new StringStream(
'1 0 obj\n' +
'<<\n' +
@ -324,6 +330,7 @@ describe('parser', function() {
it('should reject a linearization dictionary with invalid hint parameters',
function() {
// The /H parameter should be an array.
// prettier-ignore
const stream1 = new StringStream(
'1 0 obj\n' +
'<<\n' +
@ -343,6 +350,7 @@ describe('parser', function() {
'is invalid.'));
// The hint array should contain two, or four, elements.
// prettier-ignore
const stream2 = new StringStream(
'1 0 obj\n' +
'<<\n' +
@ -362,6 +370,7 @@ describe('parser', function() {
'is invalid.'));
// The hint array should not contain zero.
// prettier-ignore
const stream3 = new StringStream(
'1 0 obj\n' +
'<<\n' +