pdf.js/test/unit/parser_spec.js
mduan eb8f4e8343 Handle some illegal characters in hex string
Do not throw exception when hex strings are in the wrong format

Currently pdf.js is throwing an exception for the following hex string:

`<7 0 2 15 5 2 2 2 4 3 2 4>`

The issue is that the 15 is not a valid hex character so pdf.js ends up
throwing an exception.

This diff changes the parser to process the above hex string as follow:

`70 21 55 2 24 32` (Note: the final 4 of the hex string is ignored)

replicating the behaviour of MuPDF, and doesn't throw an exception.
2013-01-08 15:29:24 -08:00

29 lines
834 B
JavaScript

/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
'use strict';
describe('parser', function() {
describe('Lexer', function() {
it('should stop parsing numbers at the end of stream', function() {
var input = new StringStream('1.234');
var lexer = new Lexer(input);
var result = lexer.getNumber('1');
expect(result).toEqual(11.234);
});
it('should not throw exception on bad input', function() {
// '8 0 2 15 5 2 2 2 4 3 2 4'
// should be parsed as
// '80 21 55 22 24 32'
var input = new StringStream('7 0 2 15 5 2 2 2 4 3 2 4>');
var lexer = new Lexer(input);
var result = lexer.getHexString('<');
expect(result).toEqual('p!U"$2');
});
});
});