Skip to content
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

Merged
merged 2 commits into from
Jun 22, 2015
Merged

Fix string field value escaping #3088

merged 2 commits into from
Jun 22, 2015

Conversation

jwilder
Copy link
Contributor

@jwilder jwilder commented Jun 22, 2015

Commas and quotes could get escaped and parsed incorrectly if they
were both present in a string value.

Fixes #3013

@otoolep
Copy link
Contributor

otoolep commented Jun 22, 2015

CHANGELOG needs updating.


// Compile the regex that detects unquoted double quote sequences
var err error
quoteReplacer, err = regexp.Compile(`([^\\])"`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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.

jwilder added 2 commits June 22, 2015 13:17
Commas and quotes could get escaped and parsed incorrectly if they
were both present in a string value.

Fixes #3013
@@ -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] != '\\' {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@otoolep
Copy link
Contributor

otoolep commented Jun 22, 2015

+1, I see where you're going.

jwilder added a commit that referenced this pull request Jun 22, 2015
Fix string field value escaping
@jwilder jwilder merged commit cc7e59a into master Jun 22, 2015
@jwilder jwilder deleted the jw-field-values branch June 22, 2015 19:48
@jwilder jwilder mentioned this pull request Jun 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants