Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class PDFObject {
// If so, encode it as big endian UTF-16
let stringBuffer;
if (isUnicode) {
stringBuffer = swapBytes(new Buffer(`\ufeff${string}`, 'utf16le'));
stringBuffer = swapBytes(Buffer.from(`\ufeff${string}`, 'utf16le'));
} else {
stringBuffer = new Buffer(string, 'ascii');
stringBuffer = Buffer.from(string.valueOf(), 'ascii');
}

// Encrypt the string when necessary
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/object.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const PDFObject = require('../../lib/object').default;

describe('PDFObject', () => {
describe('convert', () => {
test('string literal', () => {
expect(PDFObject.convert('test')).toEqual('/test');
});

test('string literal with unicode', () => {
expect(PDFObject.convert('αβγδ')).toEqual('/αβγδ');
});

test('String object', () => {
expect(PDFObject.convert(new String('test'))).toEqual('(test)');
});

test('String object with unicode', () => {
const result = PDFObject.convert(new String('αβγδ'));
expect(result.length).toEqual(12);
expect(result).toMatchInlineSnapshot(`"(þÿ±²³´)"`);
});
});
});