-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix string field value escaping #3088
Conversation
CHANGELOG needs updating. |
|
||
// Compile the regex that detects unquoted double quote sequences | ||
var err error | ||
quoteReplacer, err = regexp.Compile(`([^\\])"`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use https://golang.org/pkg/regexp/#MustCompile, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. Forgot about that func. Updated.
@@ -604,7 +608,8 @@ func scanFieldValue(buf []byte, i int) (int, []byte) { | |||
break | |||
} | |||
|
|||
if buf[i] == '"' { | |||
// If we see a double quote, makes sure it is not escaped | |||
if buf[i] == '"' && buf[i-1] != '\\' { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If i
is zero, this might blow up, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, yes, if you call scanFieldValue(buf, 0)
directly then it can blow up but i
can't be zero during parsing because we need to scan the the field name first and it must be non-zero in length so the function is always called with a non-zero value for i
. I could special case it here too but didn't think it was necessary since the func is private and only called in one place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool on that reasoning -- thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, I see where you're going. |
Fix string field value escaping
Commas and quotes could get escaped and parsed incorrectly if they
were both present in a string value.
Fixes #3013