mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-05 19:30:30 +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
|
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)
|
name, ok := sod.Get("Type").(*PdfObjectName)
|
||||||
if !ok {
|
if !ok {
|
||||||
common.Log.Debug("ERROR: Object stream should always have a Type")
|
common.Log.Debug("ERROR: Object stream should always have a Type")
|
||||||
|
@ -526,8 +526,15 @@ func (parser *PdfParser) parseObject() (PdfObject, error) {
|
|||||||
for {
|
for {
|
||||||
bb, err := parser.reader.Peek(2)
|
bb, err := parser.reader.Peek(2)
|
||||||
if err != nil {
|
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
|
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))
|
common.Log.Trace("Peek string: %s", string(bb))
|
||||||
// Determine type.
|
// Determine type.
|
||||||
|
@ -588,6 +588,7 @@ endobj`
|
|||||||
common.Log.Debug("Xref dict: %s", xrefDict)
|
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) {
|
func TestObjectParse(t *testing.T) {
|
||||||
parser := PdfParser{}
|
parser := PdfParser{}
|
||||||
|
|
||||||
@ -601,6 +602,24 @@ func TestObjectParse(t *testing.T) {
|
|||||||
return
|
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
|
// Integer
|
||||||
rawText = "9 0 false"
|
rawText = "9 0 false"
|
||||||
parser.rs, parser.reader, parser.fileSize = makeReaderForText(rawText)
|
parser.rs, parser.reader, parser.fileSize = makeReaderForText(rawText)
|
||||||
@ -610,7 +629,7 @@ func TestObjectParse(t *testing.T) {
|
|||||||
t.Errorf("Error parsing object")
|
t.Errorf("Error parsing object")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
nump, ok := obj.(*PdfObjectInteger)
|
nump, ok = obj.(*PdfObjectInteger)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Errorf("Unable to identify integer")
|
t.Errorf("Unable to identify integer")
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user