This closes #2015, fix a v2.9.0 regression bug introduced by commit 7715c1462a
- Fix corrupted workbook generated by open the workbook generated by stream writer - Update unit tests
This commit is contained in:
parent
af190c7fdc
commit
0d5d1c53b2
9
lib.go
9
lib.go
|
@ -652,11 +652,16 @@ func getRootElement(d *xml.Decoder) []xml.Attr {
|
|||
case xml.StartElement:
|
||||
tokenIdx++
|
||||
if tokenIdx == 1 {
|
||||
var ns bool
|
||||
for i := 0; i < len(startElement.Attr); i++ {
|
||||
if startElement.Attr[i].Value == NameSpaceSpreadSheet.Value {
|
||||
startElement.Attr[i] = NameSpaceSpreadSheet
|
||||
if startElement.Attr[i].Value == NameSpaceSpreadSheet.Value &&
|
||||
startElement.Attr[i].Name == NameSpaceSpreadSheet.Name {
|
||||
ns = true
|
||||
}
|
||||
}
|
||||
if !ns {
|
||||
startElement.Attr = append(startElement.Attr, NameSpaceSpreadSheet)
|
||||
}
|
||||
return startElement.Attr
|
||||
}
|
||||
}
|
||||
|
|
|
@ -289,6 +289,10 @@ func TestBytesReplace(t *testing.T) {
|
|||
|
||||
func TestGetRootElement(t *testing.T) {
|
||||
assert.Len(t, getRootElement(xml.NewDecoder(strings.NewReader(""))), 0)
|
||||
// Test get workbook root element which all workbook XML namespace has prefix
|
||||
f := NewFile()
|
||||
d := f.xmlNewDecoder(bytes.NewReader([]byte(`<x:workbook xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main"></x:workbook>`)))
|
||||
assert.Len(t, getRootElement(d), 3)
|
||||
}
|
||||
|
||||
func TestSetIgnorableNameSpace(t *testing.T) {
|
||||
|
|
|
@ -516,7 +516,7 @@ func TestDeleteWorkbookPivotCache(t *testing.T) {
|
|||
f := NewFile()
|
||||
// Test delete workbook pivot table cache with unsupported workbook charset
|
||||
f.WorkBook = nil
|
||||
f.Pkg.Store("xl/workbook.xml", MacintoshCyrillicCharset)
|
||||
f.Pkg.Store(defaultXMLPathWorkbook, MacintoshCyrillicCharset)
|
||||
assert.EqualError(t, f.deleteWorkbookPivotCache(PivotTableOptions{pivotCacheXML: "pivotCache/pivotCacheDefinition1.xml"}), "XML syntax error on line 1: invalid UTF-8")
|
||||
|
||||
// Test delete workbook pivot table cache with unsupported workbook relationships charset
|
||||
|
|
|
@ -580,7 +580,7 @@ func TestMoveSheet(t *testing.T) {
|
|||
|
||||
// Test move sheet with unsupported workbook charset
|
||||
f.WorkBook = nil
|
||||
f.Pkg.Store("xl/workbook.xml", MacintoshCyrillicCharset)
|
||||
f.Pkg.Store(defaultXMLPathWorkbook, MacintoshCyrillicCharset)
|
||||
assert.EqualError(t, f.MoveSheet("Sheet2", "Sheet1"), "XML syntax error on line 1: invalid UTF-8")
|
||||
}
|
||||
|
||||
|
|
|
@ -597,7 +597,7 @@ func TestAddWorkbookSlicerCache(t *testing.T) {
|
|||
// Test add a workbook slicer cache with unsupported charset workbook
|
||||
f := NewFile()
|
||||
f.WorkBook = nil
|
||||
f.Pkg.Store("xl/workbook.xml", MacintoshCyrillicCharset)
|
||||
f.Pkg.Store(defaultXMLPathWorkbook, MacintoshCyrillicCharset)
|
||||
assert.EqualError(t, f.addWorkbookSlicerCache(1, ExtURISlicerCachesX15), "XML syntax error on line 1: invalid UTF-8")
|
||||
assert.NoError(t, f.Close())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue