Browse Source

Properly escape `xlsxNumFmt.FormatCode` in `Marshal()`

Sergej Zagursky 8 years ago
parent
commit
682ad561c8
1 changed files with 7 additions and 1 deletions
  1. 7 1
      xmlStyle.go

+ 7 - 1
xmlStyle.go

@@ -8,6 +8,7 @@
 package xlsx
 package xlsx
 
 
 import (
 import (
+	"bytes"
 	"encoding/xml"
 	"encoding/xml"
 	"fmt"
 	"fmt"
 	"strconv"
 	"strconv"
@@ -451,7 +452,12 @@ type xlsxNumFmt struct {
 }
 }
 
 
 func (numFmt *xlsxNumFmt) Marshal() (result string, err error) {
 func (numFmt *xlsxNumFmt) Marshal() (result string, err error) {
-	return fmt.Sprintf(`<numFmt numFmtId="%d" formatCode="%s"/>`, numFmt.NumFmtId, numFmt.FormatCode), nil
+	formatCode := &bytes.Buffer{}
+	if err := xml.EscapeText(formatCode, []byte(numFmt.FormatCode)); err != nil {
+		return "", err
+	}
+
+	return fmt.Sprintf(`<numFmt numFmtId="%d" formatCode="%s"/>`, numFmt.NumFmtId, formatCode), nil
 }
 }
 
 
 // xlsxFonts directly maps the fonts element in the namespace
 // xlsxFonts directly maps the fonts element in the namespace