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

SqlString.Trim should return the same instance for not modified string #3340

Merged
merged 2 commits into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/NHibernate.Test/SqlCommandTest/SqlStringFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ public void TrimAllParam()
Parameter p2 = Parameter.Placeholder;

SqlString sql = new SqlString(new object[] { p1, p2 });
sql = sql.Trim();

Assert.That(ReferenceEquals(sql, sql.Trim()), Is.True);
Assert.AreEqual("??", sql.ToString());
}

Expand Down
4 changes: 4 additions & 0 deletions src/NHibernate/SqlCommand/SqlString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,10 @@ public SqlString Trim()
if (_firstPartIndex < 0) return this;

GetTrimmedIndexes(out var sqlStartIndex, out var length);

if (_sqlStartIndex == sqlStartIndex && _length == length)
return this;

return length > 0
? new SqlString(this, sqlStartIndex, length)
: Empty;
Expand Down