Skip to content

Commit

Permalink
Fix #710, #635
Browse files Browse the repository at this point in the history
  • Loading branch information
hhrutter committed Sep 13, 2023
1 parent 04840dd commit 4fbc44e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
18 changes: 15 additions & 3 deletions pkg/pdfcpu/model/xreftable.go
Expand Up @@ -649,16 +649,28 @@ func (xRefTable *XRefTable) NewFileSpecDict(f, uf, desc string, indRefStreamDict

d := types.NewDict()
d.InsertName("Type", "Filespec")
d.InsertString("F", f)
d.InsertString("UF", uf)

s, err := types.EscapeUTF16String(f)
if err != nil {
return nil, err
}
d.InsertString("F", *s)

if s, err = types.EscapeUTF16String(uf); err != nil {
return nil, err
}
d.InsertString("UF", *s)

efDict := types.NewDict()
efDict.Insert("F", indRefStreamDict)
efDict.Insert("UF", indRefStreamDict)
d.Insert("EF", efDict)

if desc != "" {
d.InsertString("Desc", desc)
if s, err = types.EscapeUTF16String(desc); err != nil {
return nil, err
}
d.InsertString("Desc", *s)
}

// CI, optional, collection item dict, since V1.7
Expand Down
16 changes: 11 additions & 5 deletions pkg/pdfcpu/types/date.go
Expand Up @@ -119,12 +119,18 @@ func parseTimezone(s string, relaxed bool) (h, m int, ok bool) {

// local time equal to UT.
// "YYYYMMDDHHmmSSZ" or
// "YYYYMMDDHHmmSSZ'" if relaxed
if o == 'Z' && (len(s) == 15 || (relaxed && len(s) == 16 && s[15] == '\'')) {
return 0, 0, true
// if relaxed
// "YYYYMMDDHHmmSSZ'"
// "YYYYMMDDHHmmSSZ'0"

if o == 'Z' {
t := s[15:]
if t == "" || relaxed && (t == "'" || t == "'0") {
return 0, 0, true
}
}

// HH'mm'
// HH'mm
s = s[15:]
if s[0] == '-' {
s = s[1:]
Expand Down Expand Up @@ -336,7 +342,7 @@ func digestPopularOutOfSpecDates(s string) (time.Time, bool) {
// DateTime decodes s into a time.Time.
func DateTime(s string, relaxed bool) (time.Time, bool) {
// 7.9.4 Dates
// (D:YYYYMMDDHHmmSSOHH'mm')
// (D:YYYYMMDDHHmmSSOHH'mm)

var d time.Time

Expand Down
12 changes: 9 additions & 3 deletions pkg/pdfcpu/types/date_test.go
Expand Up @@ -55,6 +55,9 @@ func doParseDateTimeFail(s string, t *testing.T) {

func TestParseDateTime(t *testing.T) {

// (D:YYYYMMDDHHmmSSOHH'mm)
// O = -,+,Z

s := "D:2017"
doParseDateTimeOK(s, t)

Expand All @@ -80,13 +83,13 @@ func TestParseDateTime(t *testing.T) {
s = "D:20170430155901"
doParseDateTimeOK(s, t)

s = "D:20170430155901+06'59'"
s = "D:20170430155901+06'59"
doParseDateTimeOK(s, t)

s = "D:20170430155901Z00"
doParseDateTimeOK(s, t)

s = "D:20170430155901Z00'00'"
s = "D:20170430155901Z00'00"
doParseDateTimeOK(s, t)

s = "D:20210602180254-06"
Expand All @@ -101,12 +104,15 @@ func TestParseDateTime(t *testing.T) {
s = "D:20210515103719-02'00"
doParseDateTimeOK(s, t)

s = "D:20170430155901+66'A9'"
s = "D:20170430155901+66'A9"
doParseDateTimeFail(s, t)

s = "D:20201222164228Z'"
doParseDateTimeRelaxedOK(s, t)

s = "D:20230912144809Z'0"
doParseDateTimeRelaxedOK(s, t)

s = "20141117162446Z00'00'"
doParseDateTimeRelaxedOK(s, t)

Expand Down

0 comments on commit 4fbc44e

Please sign in to comment.