Skip to content

Commit

Permalink
Merge pull request #1614 from riganti/fix/make-typehash-less-volatile
Browse files Browse the repository at this point in the history
Changed typehash computation to be less volatile
  • Loading branch information
acizmarik authored Mar 9, 2023
2 parents 40f0a94 + cc24410 commit 1ec819d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/Framework/Framework/Utils/ReflectionUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ public static string GetTypeHash(this Type type)
return cache_GetTypeHash.GetOrAdd(type, t => {
using (var sha1 = SHA1.Create())
{
var typeName = t.FullName + ", " + t.Assembly.GetName().Name;
var typeName = t.ToCode() + ", " + t.Assembly.GetName().Name;
var hashBytes = sha1.ComputeHash(Encoding.UTF8.GetBytes(typeName));
return Convert.ToBase64String(hashBytes, 0, 12);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</div>
<input id="__dot_viewmodel_root" type="hidden" value="{
&quot;viewModel&quot;: {
&quot;$type&quot;: &quot;RPyCWRg9lOhkRJyH&quot;,
&quot;$type&quot;: &quot;R+sz4Xh1JrRtZJ4S&quot;,
&quot;Collection&quot;: [
&quot;A&quot;,
&quot;B&quot;
Expand All @@ -55,7 +55,7 @@
&quot;viewModule.init.HIj399FcjVwbyaIvDKFctn7Ghr0UMajY-haUgZypcHs&quot;
],
&quot;typeMetadata&quot;: {
&quot;RPyCWRg9lOhkRJyH&quot;: {
&quot;R+sz4Xh1JrRtZJ4S&quot;: {
&quot;type&quot;: &quot;object&quot;,
&quot;debugName&quot;: &quot;ViewModulesServerSideTests.TestViewModel&quot;,
&quot;properties&quot;: {
Expand Down
26 changes: 13 additions & 13 deletions src/Tests/ViewModel/ViewModelTypeMetadataSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ public static void ClassInit(TestContext context)
[DataRow(typeof(long[][]), "[['Int64']]")]
[DataRow(typeof(Type), "'Av/XciKNYBmL6ZsV'")] // unknown types should produce SHA1 hash
[DataRow(typeof(object), "{'type':'dynamic'}")]
[DataRow(typeof(Dictionary<string, string>), "[\"PVyTyqvI4Id5nYo+\"]")]
[DataRow(typeof(IDictionary<string, string>), "[\"PVyTyqvI4Id5nYo+\"]")]
[DataRow(typeof(Dictionary<int, int>), "[\"COeXIi+/gCnEgi6U\"]")]
[DataRow(typeof(Dictionary<char, object>), "[\"0AQHqpcFiaoYjUd+\"]")]
[DataRow(typeof(IDictionary<int, int>), "[\"COeXIi+/gCnEgi6U\"]")]
[DataRow(typeof(Dictionary<object, object>), "[\"y6hj7iGE5x+eLypR\"]")]
[DataRow(typeof(IDictionary<object, object>), "[\"y6hj7iGE5x+eLypR\"]")]
[DataRow(typeof(List<KeyValuePair<string, string>>), "[\"PVyTyqvI4Id5nYo+\"]")]
[DataRow(typeof(List<KeyValuePair<int, int>>), "[\"COeXIi+/gCnEgi6U\"]")]
[DataRow(typeof(List<KeyValuePair<object, object>>), "[\"y6hj7iGE5x+eLypR\"]")]
[DataRow(typeof(IList<KeyValuePair<string, string>>), "[\"PVyTyqvI4Id5nYo+\"]")]
[DataRow(typeof(IList<KeyValuePair<int, int>>), "[\"COeXIi+/gCnEgi6U\"]")]
[DataRow(typeof(IList<KeyValuePair<object, object>>), "[\"y6hj7iGE5x+eLypR\"]")]
[DataRow(typeof(Dictionary<string, string>), "[\"C+Vo5gho7HtxCAAr\"]")]
[DataRow(typeof(IDictionary<string, string>), "[\"C+Vo5gho7HtxCAAr\"]")]
[DataRow(typeof(Dictionary<int, int>), "[\"VnTd1CsMIOOD62hn\"]")]
[DataRow(typeof(Dictionary<char, object>), "[\"YVHqjWtxjfqkABaT\"]")]
[DataRow(typeof(IDictionary<int, int>), "[\"VnTd1CsMIOOD62hn\"]")]
[DataRow(typeof(Dictionary<object, object>), "[\"ReXn90XOeD3pn81A\"]")]
[DataRow(typeof(IDictionary<object, object>), "[\"ReXn90XOeD3pn81A\"]")]
[DataRow(typeof(List<KeyValuePair<string, string>>), "[\"C+Vo5gho7HtxCAAr\"]")]
[DataRow(typeof(List<KeyValuePair<int, int>>), "[\"VnTd1CsMIOOD62hn\"]")]
[DataRow(typeof(List<KeyValuePair<object, object>>), "[\"ReXn90XOeD3pn81A\"]")]
[DataRow(typeof(IList<KeyValuePair<string, string>>), "[\"C+Vo5gho7HtxCAAr\"]")]
[DataRow(typeof(IList<KeyValuePair<int, int>>), "[\"VnTd1CsMIOOD62hn\"]")]
[DataRow(typeof(IList<KeyValuePair<object, object>>), "[\"ReXn90XOeD3pn81A\"]")]
// these hashes are dependent on the target framework - the latest update of hashes is updated to net60
public void ViewModelTypeMetadata_TypeName(Type type, string expected)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"zwwfdylYHjdj7S5w": {
"zyiwtciFfjs2370j": {
"type": "object",
"properties": {
"ChildFirstRequest": {
"type": "5PrhilQGdc+tT1tU",
"type": "eyIKEC0oWfJQeAVV",
"post": "no",
"update": "no"
},
Expand All @@ -13,7 +13,7 @@
},
"NestedList": {
"type": [
"5PrhilQGdc+tT1tU"
"eyIKEC0oWfJQeAVV"
]
},
"ObjectProperty": {
Expand All @@ -28,7 +28,7 @@
"type": [
{
"type": "nullable",
"inner": "3X0sQPLUhQryBTP0"
"inner": "tpU8HGbU+2oMuuUB"
}
]
},
Expand All @@ -45,7 +45,7 @@
}
}
},
"5PrhilQGdc+tT1tU": {
"eyIKEC0oWfJQeAVV": {
"type": "object",
"properties": {
"InPathOnly": {
Expand All @@ -69,7 +69,7 @@
}
}
},
"3X0sQPLUhQryBTP0": {
"tpU8HGbU+2oMuuUB": {
"type": "enum",
"isFlags": true,
"values": {
Expand Down

0 comments on commit 1ec819d

Please sign in to comment.