@@ -178,13 +178,13 @@ func Parse(ctx context.Context, r io.Reader) (map[string]string, error) {
178178 case b [0 ] == '#' :
179179 continue
180180 }
181- eq := bytes .IndexRune (b , '=' )
182- if eq == - 1 {
181+ if ! bytes .ContainsRune (b , '=' ) {
183182 return nil , fmt .Errorf ("osrelease: malformed line %q" , s .Text ())
184183 }
185184 // Also handling spaces here matches what systemd seems to do.
186- key := strings .TrimSpace (string (b [:eq ]))
187- value := strings .TrimSpace (string (b [eq + 1 :]))
185+ key , value , _ := strings .Cut (string (b ), "=" )
186+ key = strings .TrimSpace (key )
187+ value = strings .TrimSpace (value )
188188
189189 // The value side is defined to follow shell-like quoting rules, which I
190190 // take to mean:
@@ -201,11 +201,12 @@ func Parse(ctx context.Context, r io.Reader) (map[string]string, error) {
201201 //
202202 // With these in mind, the arms of the switch below implement the first
203203 // case and a limited version of the second.
204- switch value [0 ] {
205- case '\'' :
204+ switch {
205+ case len (value ) == 0 :
206+ case value [0 ] == '\'' :
206207 value = strings .TrimFunc (value , func (r rune ) bool { return r == '\'' })
207208 value = strings .ReplaceAll (value , `'\''` , `'` )
208- case '"' :
209+ case value [ 0 ] == '"' :
209210 // This only implements the metacharacters that are called out in
210211 // the os-release documentation.
211212 value = strings .TrimFunc (value , func (r rune ) bool { return r == '"' })
0 commit comments