summaryrefslogtreecommitdiff
path: root/styles.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2020-09-18 22:20:58 +0800
committerxuri <xuri.me@gmail.com>2020-09-18 22:20:58 +0800
commit324f87bcaed9ec775c0b79627956a093ad481d36 (patch)
tree56a779bde041b3dae82ab0f2e827ed0021c3d602 /styles.go
parent96917e4617c9e7eb15c0ee1723a042f169321430 (diff)
add checking and limits for the worksheet
Diffstat (limited to 'styles.go')
-rw-r--r--styles.go37
1 files changed, 23 insertions, 14 deletions
diff --git a/styles.go b/styles.go
index c3a2393..14bcecc 100644
--- a/styles.go
+++ b/styles.go
@@ -1037,10 +1037,26 @@ func (f *File) sharedStringsWriter() {
// parseFormatStyleSet provides a function to parse the format settings of the
// cells and conditional formats.
-func parseFormatStyleSet(style string) (*Style, error) {
- format := Style{}
- err := json.Unmarshal([]byte(style), &format)
- return &format, err
+func parseFormatStyleSet(style interface{}) (*Style, error) {
+ fs := Style{}
+ var err error
+ switch v := style.(type) {
+ case string:
+ err = json.Unmarshal([]byte(v), &fs)
+ case *Style:
+ fs = *v
+ default:
+ err = errors.New("invalid parameter type")
+ }
+ if fs.Font != nil {
+ if len(fs.Font.Family) > MaxFontFamilyLength {
+ return &fs, errors.New("the length of the font family name must be smaller than or equal to 31")
+ }
+ if fs.Font.Size > MaxFontSize {
+ return &fs, errors.New("font size must be between 1 and 409 points")
+ }
+ }
+ return &fs, err
}
// NewStyle provides a function to create the style for cells by given JSON or
@@ -1909,16 +1925,9 @@ func (f *File) NewStyle(style interface{}) (int, error) {
var fs *Style
var err error
var cellXfsID, fontID, borderID, fillID int
- switch v := style.(type) {
- case string:
- fs, err = parseFormatStyleSet(v)
- if err != nil {
- return cellXfsID, err
- }
- case *Style:
- fs = v
- default:
- return cellXfsID, errors.New("invalid parameter type")
+ fs, err = parseFormatStyleSet(style)
+ if err != nil {
+ return cellXfsID, err
}
if fs.DecimalPlaces == 0 {
fs.DecimalPlaces = 2