Skip to content

Commit

Permalink
undo skipSignal implementation for rune parser
Browse files Browse the repository at this point in the history
  • Loading branch information
jtagcat committed Jun 26, 2022
1 parent 54273cd commit 48f99c7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pkg/encoding/ssh_config/0_line.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,15 @@ func DecodeValue(s string) (strings []RawValue, comment string, err error) {
// func inspired by https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/openssh-8.8.tar.gz misc.c#1889 and strings.FieldsFunc()
currentString, quoted := "", 0
maxPos := utf8.RuneCountInString(s) - 1 // prevents index (of next rune) out of range
skipSignal := false

runereader:
for pos, rune := range s {
if skipSignal {
skipSignal = false
continue
}

if rune == '\\' { // single backslash
if pos == maxPos { // last rune
currentString += "\\\\" // 2 backslashes
Expand All @@ -98,7 +104,7 @@ runereader:
currentString += "\\\\" // 2 backslashes
continue
}
pos++ // skip next rune
skipSignal = true // skip next rune
continue
}

Expand Down Expand Up @@ -184,7 +190,13 @@ func EncodeValue(values []RawValue, comment string) (encoded string, err error)
encoded += "\""
}

skipSignal := false
for pos, rune := range v.Value {
if skipSignal {
skipSignal = false
continue
}

if rune == '\\' { // single backslash
switch string(v.Value[pos+1]) {
case "'":
Expand All @@ -202,7 +214,7 @@ func EncodeValue(values []RawValue, comment string) (encoded string, err error)
err = ErrWarnSingleBackslashTransformed
continue
}
pos++
skipSignal = true
continue
}
encoded += string(rune)
Expand Down
1 change: 1 addition & 0 deletions pkg/encoding/ssh_config/0_line_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func TestDecodeValue(t *testing.T) {
"Inv'alid": {nil, "", ErrInvalidQuoting},
"\"": {nil, "", ErrInvalidQuoting},
"'": {nil, "", ErrInvalidQuoting},
"Esc\\'quot": {[]RawValue{{"Esc'quot", 0}}, "", nil}, //: \'
"\"Valid\"": {[]RawValue{{"Valid", 2}}, "", nil},
"\"V'alid\"": {[]RawValue{{"V'alid", 2}}, "", nil},
"String1 String2": {[]RawValue{{"String1", 0}, {"String2", 0}}, "", nil},
Expand Down

0 comments on commit 48f99c7

Please sign in to comment.