bufio.Scanner has an internal limit on the maximum token (= line)
length. We want to support larger lines in the future.
func ParseGroups(r io.Reader) ([]Group, error) {
var res []Group
func ParseGroups(r io.Reader) ([]Group, error) {
var res []Group
- s := bufio.NewScanner(r)
- for s.Scan() {
- t := s.Text()
+ s := bufio.NewReader(r)
+ for {
+ t, err := s.ReadString('\n')
+ if err != nil {
+ if err == io.EOF {
+ break
+ }
+ return nil, err
+ }
x := strings.Split(t, ":")
if len(x) != 4 {
x := strings.Split(t, ":")
if len(x) != 4 {
return nil, errors.Wrapf(err, "invalid gid in line %q", t)
}
return nil, errors.Wrapf(err, "invalid gid in line %q", t)
}
+ // ReadString() contains the delimiter
+ x[3] = strings.TrimSuffix(x[3], "\n")
+
var members []string
// No members must result in empty slice, not slice with the
// empty string
var members []string
// No members must result in empty slice, not slice with the
// empty string
- err := s.Err()
- if err != nil {
- return nil, err
- }
func ParsePasswds(r io.Reader) ([]Passwd, error) {
var res []Passwd
func ParsePasswds(r io.Reader) ([]Passwd, error) {
var res []Passwd
- s := bufio.NewScanner(r)
- for s.Scan() {
- t := s.Text()
+ s := bufio.NewReader(r)
+ for {
+ t, err := s.ReadString('\n')
+ if err != nil {
+ if err == io.EOF {
+ break
+ }
+ return nil, err
+ }
x := strings.Split(t, ":")
if len(x) != 7 {
x := strings.Split(t, ":")
if len(x) != 7 {
Gid: gid,
Gecos: x[4],
Dir: x[5],
Gid: gid,
Gecos: x[4],
Dir: x[5],
+ // ReadString() contains the delimiter
+ Shell: strings.TrimSuffix(x[6], "\n"),
- err := s.Err()
- if err != nil {
- return nil, err
- }
-