Skip to content

Commit

Permalink
Also remove leading whitespace in SplitMarginComments.
Browse files Browse the repository at this point in the history
This was separated from the previous diff because it impacts query plans, although in seemingly-harmless way.

Signed-off-by: David Weitzman <[email protected]>
  • Loading branch information
dweitzman authored and bramp committed Jun 6, 2018
1 parent c87823d commit 112deeb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func SplitMarginComments(sql string) (query string, comments MarginComments) {
Leading: strings.TrimLeftFunc(sql[:leadingEnd], unicode.IsSpace),
Trailing: strings.TrimRightFunc(sql[trailingStart:], unicode.IsSpace),
}
return strings.TrimRightFunc(sql[leadingEnd:trailingStart], unicode.IsSpace), comments
return strings.TrimFunc(sql[leadingEnd:trailingStart], unicode.IsSpace), comments
}

// StripLeadingComments trims the SQL string and removes any leading comments
Expand Down
12 changes: 7 additions & 5 deletions comments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ func TestSplitComments(t *testing.T) {
outSQL: "foo",
outLeadingComments: "/* before */ ",
outTrailingComments: " /* bar */",
}, {
input: "/* before1 */ /* before2 */ foo /* after1 */ /* after2 */",
outSQL: "foo",
outLeadingComments: "/* before1 */ /* before2 */ ",
outTrailingComments: " /* after1 */ /* after2 */",
}, {
input: "/** before */ foo /** bar */",
outSQL: "foo",
Expand Down Expand Up @@ -110,11 +115,8 @@ func TestSplitComments(t *testing.T) {
outLeadingComments: "",
outTrailingComments: "",
}, {
input: " foo ",
// NOTE(dweitzman): Preserving leading whitespace because the WhereClause entries for 'update'
// in exec_cases.txt have leading whitespace and if we trim it here that will change. It may be
// safe to change, but changing query plans is not an intended effect of this diff.
outSQL: " foo",
input: " foo ",
outSQL: "foo",
outLeadingComments: "",
outTrailingComments: "",
}}
Expand Down

0 comments on commit 112deeb

Please sign in to comment.