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

parse literals more like Postgres #1807

Merged
merged 2 commits into from
Jul 26, 2015
Merged

parse literals more like Postgres #1807

merged 2 commits into from
Jul 26, 2015

Conversation

tbg
Copy link
Member

@tbg tbg commented Jul 25, 2015

  • rewrote SQL escaping. It'll output an escaped string when it has to, or when
    a single-quote or backslash appears (the former could be written as '', but
    this is more awkward to implement; the latter needs escaping only in an
    escaped string, which would require an extra pass through the string prior
    to beginning the encoding - not worth it).
  • no escaping of "; Postgres doesn't do it
  • dissect and update all the test cases affected by this and add some new ones.

found via go-fuzz, ping @dvyukov.

data0: "INSERT INTO O VALUES ('\0\n\n')"
data1: "INSERT INTO O VALUES ('\0\n\n')"
panic: not equal

} else {
buf = append(buf, '\\')
buf = append(buf, encodedChar)
}
}
buf = append(buf, '\'')
if strMod != 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why don't you append the strMod byte above where the opening ' is appended?

Copy link
Member Author

Choose a reason for hiding this comment

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

done. Remnants from earlier code where I hoped not to have to iterate twice.

@petermattis
Copy link
Collaborator

LGTM

@tbg tbg force-pushed the sql_literals branch 3 times, most recently from f440628 to 0c9245c Compare July 26, 2015 13:43
tbg added 2 commits July 26, 2015 11:39
with this change

* rewrote SQL escaping. It'll output an escaped string when it has to, or when
  a single-quote or backslash appears (the former could be written as '', but
  this is more awkward to implement; the latter needs escaping only in an
  escaped string, which would require an extra pass through the string prior
  to beginning the encoding - not worth it).
* no escaping of "; Postgres doesn't do it
* dissect and update all the test cases affected by this and add some new ones.

found via go-fuzz, ping @dvyukov.
tbg added a commit that referenced this pull request Jul 26, 2015
parse literals more like Postgres
@tbg tbg merged commit cdd21fd into cockroachdb:master Jul 26, 2015
@tbg tbg removed the PTAL label Jul 26, 2015
@tbg tbg deleted the sql_literals branch July 26, 2015 15:55
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.

None yet

2 participants