vendor/gopkg.in/ini.v1/parser.go
changeset 256 6d9efbef00a9
parent 251 1c52a0eeb952
child 260 445e01aede7e
equal deleted inserted replaced
255:4f153a23adab 256:6d9efbef00a9
    82 
    82 
    83 	switch {
    83 	switch {
    84 	case mask[0] == 254 && mask[1] == 255:
    84 	case mask[0] == 254 && mask[1] == 255:
    85 		fallthrough
    85 		fallthrough
    86 	case mask[0] == 255 && mask[1] == 254:
    86 	case mask[0] == 255 && mask[1] == 254:
    87 		p.buf.Read(mask)
    87 		_, err = p.buf.Read(mask)
       
    88 		if err != nil {
       
    89 			return err
       
    90 		}
    88 	case mask[0] == 239 && mask[1] == 187:
    91 	case mask[0] == 239 && mask[1] == 187:
    89 		mask, err := p.buf.Peek(3)
    92 		mask, err := p.buf.Peek(3)
    90 		if err != nil && err != io.EOF {
    93 		if err != nil && err != io.EOF {
    91 			return err
    94 			return err
    92 		} else if len(mask) < 3 {
    95 		} else if len(mask) < 3 {
    93 			return nil
    96 			return nil
    94 		}
    97 		}
    95 		if mask[2] == 191 {
    98 		if mask[2] == 191 {
    96 			p.buf.Read(mask)
    99 			_, err = p.buf.Read(mask)
       
   100 			if err != nil {
       
   101 				return err
       
   102 			}
    97 		}
   103 		}
    98 	}
   104 	}
    99 	return nil
   105 	return nil
   100 }
   106 }
   101 
   107 
   133 	} else if line[0] == '`' {
   139 	} else if line[0] == '`' {
   134 		keyQuote = "`"
   140 		keyQuote = "`"
   135 	}
   141 	}
   136 
   142 
   137 	// Get out key name
   143 	// Get out key name
   138 	endIdx := -1
   144 	var endIdx int
   139 	if len(keyQuote) > 0 {
   145 	if len(keyQuote) > 0 {
   140 		startIdx := len(keyQuote)
   146 		startIdx := len(keyQuote)
   141 		// FIXME: fail case -> """"""name"""=value
   147 		// FIXME: fail case -> """"""name"""=value
   142 		pos := strings.Index(line[startIdx:], keyQuote)
   148 		pos := strings.Index(line[startIdx:], keyQuote)
   143 		if pos == -1 {
   149 		if pos == -1 {
   179 			}
   185 			}
   180 			break
   186 			break
   181 		}
   187 		}
   182 		val += next
   188 		val += next
   183 		if p.isEOF {
   189 		if p.isEOF {
   184 			return "", fmt.Errorf("missing closing key quote from '%s' to '%s'", line, next)
   190 			return "", fmt.Errorf("missing closing key quote from %q to %q", line, next)
   185 		}
   191 		}
   186 	}
   192 	}
   187 	return val, nil
   193 	return val, nil
   188 }
   194 }
   189 
   195 
   369 		return fmt.Errorf("BOM: %v", err)
   375 		return fmt.Errorf("BOM: %v", err)
   370 	}
   376 	}
   371 
   377 
   372 	// Ignore error because default section name is never empty string.
   378 	// Ignore error because default section name is never empty string.
   373 	name := DefaultSection
   379 	name := DefaultSection
   374 	if f.options.Insensitive {
   380 	if f.options.Insensitive || f.options.InsensitiveSections {
   375 		name = strings.ToLower(DefaultSection)
   381 		name = strings.ToLower(DefaultSection)
   376 	}
   382 	}
   377 	section, _ := f.NewSection(name)
   383 	section, _ := f.NewSection(name)
   378 
   384 
   379 	// This "last" is not strictly equivalent to "previous one" if current key is not the first nested key
   385 	// This "last" is not strictly equivalent to "previous one" if current key is not the first nested key
   411 		}
   417 		}
   412 
   418 
   413 		if f.options.AllowNestedValues &&
   419 		if f.options.AllowNestedValues &&
   414 			isLastValueEmpty && len(line) > 0 {
   420 			isLastValueEmpty && len(line) > 0 {
   415 			if line[0] == ' ' || line[0] == '\t' {
   421 			if line[0] == ' ' || line[0] == '\t' {
   416 				lastRegularKey.addNestedValue(string(bytes.TrimSpace(line)))
   422 				err = lastRegularKey.addNestedValue(string(bytes.TrimSpace(line)))
       
   423 				if err != nil {
       
   424 					return err
       
   425 				}
   417 				continue
   426 				continue
   418 			}
   427 			}
   419 		}
   428 		}
   420 
   429 
   421 		line = bytes.TrimLeftFunc(line, unicode.IsSpace)
   430 		line = bytes.TrimLeftFunc(line, unicode.IsSpace)
   458 			p.count = 1
   467 			p.count = 1
   459 
   468 
   460 			inUnparseableSection = false
   469 			inUnparseableSection = false
   461 			for i := range f.options.UnparseableSections {
   470 			for i := range f.options.UnparseableSections {
   462 				if f.options.UnparseableSections[i] == name ||
   471 				if f.options.UnparseableSections[i] == name ||
   463 					(f.options.Insensitive && strings.ToLower(f.options.UnparseableSections[i]) == strings.ToLower(name)) {
   472 					((f.options.Insensitive || f.options.InsensitiveSections) && strings.EqualFold(f.options.UnparseableSections[i], name)) {
   464 					inUnparseableSection = true
   473 					inUnparseableSection = true
   465 					continue
   474 					continue
   466 				}
   475 				}
   467 			}
   476 			}
   468 			continue
   477 			continue