Skip to content

Commit

Permalink
only add application/xml content type when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
qmuntal committed Jan 26, 2021
1 parent 26e1664 commit 9a77c04
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
6 changes: 1 addition & 5 deletions package.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ func (p *pkg) add(part *Part) error {
if err := part.validate(); err != nil {
return err
}
name := part.Name
if !strings.EqualFold(name, contentTypesName) {
name = NormalizePartName(part.Name)
}
name = strings.ToUpper(name)
name := strings.ToUpper(NormalizePartName(part.Name))
if p.partExists(name) {
return newError(112, part.Name)
}
Expand Down
Binary file modified testdata/component.3mf
Binary file not shown.
8 changes: 6 additions & 2 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func NewWriter(w io.Writer) *Writer {
parts: make(map[string]struct{}, 0),
contentTypes: contentTypes{
defaults: map[string]string{
"xml": "application/xml",
"rels": relationshipContentType,
},
overrides: map[string]string{},
Expand Down Expand Up @@ -165,7 +164,12 @@ func (w *Writer) createCoreProperties() error {

func (w *Writer) createContentTypes() error {
// ISO/IEC 29500-2 M3.10
cw, err := w.addToPackage(&Part{Name: contentTypesName, ContentType: "application/xml"}, CompressionNormal)
fh := &zip.FileHeader{
Name: zipName(contentTypesName),
Modified: time.Now(),
}
w.setCompressor(fh, CompressionNormal)
cw, err := w.w.CreateHeader(fh)
if err != nil {
return err
}
Expand Down
3 changes: 0 additions & 3 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ func TestWriter_Close(t *testing.T) {
p := newPackage()
p.contentTypes.add("/a.xml", "a/b")
p.contentTypes.add("/b.xml", "c/d")
pC := newPackage()
pC.parts["/[CONTENT_TYPES].XML"] = struct{}{}
pCore := newPackage()
pCore.parts["/PROPS/CORE.XML"] = struct{}{}
pRel := newPackage()
Expand All @@ -39,7 +37,6 @@ func TestWriter_Close(t *testing.T) {
wantErr bool
}{
{"base", NewWriter(&bytes.Buffer{}), false},
{"invalidContentType", &Writer{p: pC, w: zip.NewWriter(&bytes.Buffer{})}, true},
{"withCt", &Writer{p: p, w: zip.NewWriter(&bytes.Buffer{})}, false},
{"invalidPartRel", &Writer{p: newPackage(), w: zip.NewWriter(&bytes.Buffer{}), last: &Part{Name: "/b.xml", Relationships: []*Relationship{{}}}}, true},
{"invalidOwnRel", &Writer{p: newPackage(), w: zip.NewWriter(&bytes.Buffer{}), Relationships: []*Relationship{{}}}, true},
Expand Down

0 comments on commit 9a77c04

Please sign in to comment.