@@ -355,6 +355,10 @@ func parseRules(input []interface{}, curRegion *region) (ru *rules, err error) {
355355
356356 switch object := val .(type ) {
357357 case string :
358+ if object == "" {
359+ return nil , fmt .Errorf ("Empty rule %s" , k )
360+ }
361+
358362 if k == "include" {
359363 ru .includes = append (ru .includes , object )
360364 } else {
@@ -408,30 +412,56 @@ func parseRegion(group string, regionInfo map[interface{}]interface{}, prevRegio
408412 r .group = groupNum
409413 r .parent = prevRegion
410414
411- r .start , err = regexp .Compile (regionInfo ["start" ].(string ))
415+ // start is mandatory
416+ if start , ok := regionInfo ["start" ]; ok {
417+ start := start .(string )
418+ if start == "" {
419+ return nil , fmt .Errorf ("Empty start in %s" , group )
420+ }
412421
413- if err != nil {
414- return nil , err
422+ r .start , err = regexp .Compile (start )
423+ if err != nil {
424+ return nil , err
425+ }
426+ } else {
427+ return nil , fmt .Errorf ("Missing start in %s" , group )
415428 }
416429
417- r .end , err = regexp .Compile (regionInfo ["end" ].(string ))
430+ // end is mandatory
431+ if end , ok := regionInfo ["end" ]; ok {
432+ end := end .(string )
433+ if end == "" {
434+ return nil , fmt .Errorf ("Empty end in %s" , group )
435+ }
418436
419- if err != nil {
420- return nil , err
437+ r .end , err = regexp .Compile (end )
438+ if err != nil {
439+ return nil , err
440+ }
441+ } else {
442+ return nil , fmt .Errorf ("Missing end in %s" , group )
421443 }
422444
423445 // skip is optional
424- if _ , ok := regionInfo ["skip" ]; ok {
425- r .skip , err = regexp .Compile (regionInfo ["skip" ].(string ))
446+ if skip , ok := regionInfo ["skip" ]; ok {
447+ skip := skip .(string )
448+ if skip == "" {
449+ return nil , fmt .Errorf ("Empty skip in %s" , group )
450+ }
426451
452+ r .skip , err = regexp .Compile (skip )
427453 if err != nil {
428454 return nil , err
429455 }
430456 }
431457
432458 // limit-color is optional
433- if _ , ok := regionInfo ["limit-group" ]; ok {
434- groupStr := regionInfo ["limit-group" ].(string )
459+ if groupStr , ok := regionInfo ["limit-group" ]; ok {
460+ groupStr := groupStr .(string )
461+ if groupStr == "" {
462+ return nil , fmt .Errorf ("Empty limit-group in %s" , group )
463+ }
464+
435465 if _ , ok := Groups [groupStr ]; ! ok {
436466 numGroups ++
437467 Groups [groupStr ] = numGroups
0 commit comments