Skip to content

Commit

Permalink
[Release 5.0] Fix Null Reference Exception on assigning null to SqlCo…
Browse files Browse the repository at this point in the history
…nnectionStringBuilder.Encrypt (#1784)

* [Release 5.0] Fix Null Reference Exception on assigning null to SqlConnectionStringBuilder.Encrypt

* Remove incompatible tests
  • Loading branch information
cheenamalhotra authored Oct 5, 2022
1 parent 2d03ca3 commit ee27832
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<format type="text/markdown"><![CDATA[
## Remarks
Implicit conversions have been added to maintain backwards compatibility with boolean behahavior for the <xref:Microsoft.Data.SqlClient.SqlConnectionStringBuilder.Encrypt%2A> property. When converting from a boolean, a value of `true` converts to <xref:Microsoft.Data.SqlClient.SqlConnectionEncryptOption.Mandatory%2A> and a value of `false` converts to <xref:Microsoft.Data.SqlClient.SqlConnectionEncryptOption.Optional%2A>. When converting to a boolean, <xref:Microsoft.Data.SqlClient.SqlConnectionEncryptOption.Mandatory%2A> and <xref:Microsoft.Data.SqlClient.SqlConnectionEncryptOption.Strict%2A> convert to `true` and <xref:Microsoft.Data.SqlClient.SqlConnectionEncryptOption.Optional%2A> converts `false`.
Implicit conversions have been added to maintain backwards compatibility with boolean behahavior for the <xref:Microsoft.Data.SqlClient.SqlConnectionStringBuilder.Encrypt%2A> property. When converting from a boolean, a value of `true` converts to <xref:Microsoft.Data.SqlClient.SqlConnectionEncryptOption.Mandatory%2A> and a value of `false` converts to <xref:Microsoft.Data.SqlClient.SqlConnectionEncryptOption.Optional%2A>. When converting to a boolean, <xref:Microsoft.Data.SqlClient.SqlConnectionEncryptOption.Mandatory%2A>, <xref:Microsoft.Data.SqlClient.SqlConnectionEncryptOption.Strict%2A> , and `null` convert to `true` and <xref:Microsoft.Data.SqlClient.SqlConnectionEncryptOption.Optional%2A> converts `false`.
]]></format>
</remarks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1237,8 +1237,9 @@ public SqlConnectionEncryptOption Encrypt
get => _encrypt;
set
{
SetSqlConnectionEncryptionValue(value);
_encrypt = value;
SqlConnectionEncryptOption newValue = value ?? DbConnectionStringDefaults.Encrypt;
SetSqlConnectionEncryptionValue(newValue);
_encrypt = newValue;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ public void ConnectionBuilderEncryptBackwardsCompatibility()
builder.Encrypt = SqlConnectionEncryptOption.Strict;
Assert.Equal("Encrypt=Strict", builder.ConnectionString);
Assert.True(builder.Encrypt);

builder.Encrypt = null;
Assert.Equal("Encrypt=True", builder.ConnectionString);
Assert.True(builder.Encrypt);
}

internal void ExecuteConnectionStringTests(string connectionString)
Expand Down

0 comments on commit ee27832

Please sign in to comment.