Skip to content

Commit 112deeb

Browse files
dweitzmanbramp
authored andcommitted
Also remove leading whitespace in SplitMarginComments.
This was separated from the previous diff because it impacts query plans, although in seemingly-harmless way. Signed-off-by: David Weitzman <[email protected]>
1 parent c87823d commit 112deeb

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

comments.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func SplitMarginComments(sql string) (query string, comments MarginComments) {
111111
Leading: strings.TrimLeftFunc(sql[:leadingEnd], unicode.IsSpace),
112112
Trailing: strings.TrimRightFunc(sql[trailingStart:], unicode.IsSpace),
113113
}
114-
return strings.TrimRightFunc(sql[leadingEnd:trailingStart], unicode.IsSpace), comments
114+
return strings.TrimFunc(sql[leadingEnd:trailingStart], unicode.IsSpace), comments
115115
}
116116

117117
// StripLeadingComments trims the SQL string and removes any leading comments

comments_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ func TestSplitComments(t *testing.T) {
7979
outSQL: "foo",
8080
outLeadingComments: "/* before */ ",
8181
outTrailingComments: " /* bar */",
82+
}, {
83+
input: "/* before1 */ /* before2 */ foo /* after1 */ /* after2 */",
84+
outSQL: "foo",
85+
outLeadingComments: "/* before1 */ /* before2 */ ",
86+
outTrailingComments: " /* after1 */ /* after2 */",
8287
}, {
8388
input: "/** before */ foo /** bar */",
8489
outSQL: "foo",
@@ -110,11 +115,8 @@ func TestSplitComments(t *testing.T) {
110115
outLeadingComments: "",
111116
outTrailingComments: "",
112117
}, {
113-
input: " foo ",
114-
// NOTE(dweitzman): Preserving leading whitespace because the WhereClause entries for 'update'
115-
// in exec_cases.txt have leading whitespace and if we trim it here that will change. It may be
116-
// safe to change, but changing query plans is not an intended effect of this diff.
117-
outSQL: " foo",
118+
input: " foo ",
119+
outSQL: "foo",
118120
outLeadingComments: "",
119121
outTrailingComments: "",
120122
}}

0 commit comments

Comments
 (0)