Skip to content

Commit 2917465

Browse files
authored
SqlString.Trim should return the same instance for not modified string (#3340)
1 parent 90d50c0 commit 2917465

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/NHibernate.Test/SqlCommandTest/SqlStringFixture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ public void TrimAllParam()
263263
Parameter p2 = Parameter.Placeholder;
264264

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

267+
Assert.That(ReferenceEquals(sql, sql.Trim()), Is.True);
268268
Assert.AreEqual("??", sql.ToString());
269269
}
270270

src/NHibernate/SqlCommand/SqlString.cs

+4
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,10 @@ public SqlString Trim()
702702
if (_firstPartIndex < 0) return this;
703703

704704
GetTrimmedIndexes(out var sqlStartIndex, out var length);
705+
706+
if (_sqlStartIndex == sqlStartIndex && _length == length)
707+
return this;
708+
705709
return length > 0
706710
? new SqlString(this, sqlStartIndex, length)
707711
: Empty;

0 commit comments

Comments
 (0)