mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-04 22:17:22 +08:00
Fix numeric parsing bug when only a single number. Added testcase.
This commit is contained in:
parent
0686b01fa9
commit
443b168e48
@ -85,7 +85,7 @@ func (parser *PdfParser) lookupObjectViaOS(sobjNumber int, objNum int) (PdfObjec
|
||||
}
|
||||
|
||||
sod := so.PdfObjectDictionary
|
||||
common.Log.Trace("so d: %s\n", *sod)
|
||||
common.Log.Trace("so d: %s\n", sod.String())
|
||||
name, ok := sod.Get("Type").(*PdfObjectName)
|
||||
if !ok {
|
||||
common.Log.Debug("ERROR: Object stream should always have a Type")
|
||||
|
@ -526,8 +526,15 @@ func (parser *PdfParser) parseObject() (PdfObject, error) {
|
||||
for {
|
||||
bb, err := parser.reader.Peek(2)
|
||||
if err != nil {
|
||||
// If EOFs after 1 byte then should still try to continue parsing.
|
||||
if err != io.EOF || len(bb) == 0 {
|
||||
return nil, err
|
||||
}
|
||||
if len(bb) == 1 {
|
||||
// Add space as code below is expecting 2 bytes.
|
||||
bb = append(bb, ' ')
|
||||
}
|
||||
}
|
||||
|
||||
common.Log.Trace("Peek string: %s", string(bb))
|
||||
// Determine type.
|
||||
|
@ -588,6 +588,7 @@ endobj`
|
||||
common.Log.Debug("Xref dict: %s", xrefDict)
|
||||
}
|
||||
|
||||
// TODO(gunnsth): Clear up. Should define clear inputs and expectation data and then run it.
|
||||
func TestObjectParse(t *testing.T) {
|
||||
parser := PdfParser{}
|
||||
|
||||
@ -601,6 +602,24 @@ func TestObjectParse(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
// Integer
|
||||
rawText = "0"
|
||||
parser.rs, parser.reader, parser.fileSize = makeReaderForText(rawText)
|
||||
obj, err = parser.parseObject()
|
||||
if err != nil {
|
||||
t.Errorf("Error parsing object: %v", err)
|
||||
return
|
||||
}
|
||||
nump, ok := obj.(*PdfObjectInteger)
|
||||
if !ok {
|
||||
t.Errorf("Unable to identify integer")
|
||||
return
|
||||
}
|
||||
if *nump != 0 {
|
||||
t.Errorf("Wrong value, expecting 9 (%d)", *nump)
|
||||
return
|
||||
}
|
||||
|
||||
// Integer
|
||||
rawText = "9 0 false"
|
||||
parser.rs, parser.reader, parser.fileSize = makeReaderForText(rawText)
|
||||
@ -610,7 +629,7 @@ func TestObjectParse(t *testing.T) {
|
||||
t.Errorf("Error parsing object")
|
||||
return
|
||||
}
|
||||
nump, ok := obj.(*PdfObjectInteger)
|
||||
nump, ok = obj.(*PdfObjectInteger)
|
||||
if !ok {
|
||||
t.Errorf("Unable to identify integer")
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user