Skip to content

Commit d1536f3

Browse files
Treat null/missing CmpContext and IsMasterPage as equivalent in GetGxObject
HttpAjaxContext.GetGxObject(JArray, CmpContext, IsMasterPage) iterates the array looking for an entry that matches the (CmpContext, IsMasterPage) pair. The previous lookup called obj['CmpContext'].ToString() and obj['IsMasterPage'].ToString() directly — when the array entry didn't carry those keys, the indexer returned null and ToString() threw NullReferenceException, which fell into the catch and made the function return null, breaking the callers (ajax_rsp_assign_attri and similar). Make the comparison null-safe and treat 'missing/null/empty' as semantically equivalent to the default value: - CmpContext: a missing/empty entry matches a null-or-empty parameter. - IsMasterPage: a missing/empty entry matches IsMasterPage == false (default for bool). Comparison is case-insensitive against IsMasterPage.ToString(). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> (cherry picked from commit 883f4bb) # Conflicts: # dotnet/src/dotnetframework/GxClasses/Core/Web/HttpAjaxContext.cs
1 parent 349543d commit d1536f3

1 file changed

Lines changed: 23 additions & 26 deletions

File tree

dotnet/src/dotnetframework/GxClasses/Core/Web/HttpAjaxContext.cs

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -279,41 +279,38 @@ public void ajax_rspEndCmp()
279279
}
280280

281281
private JObject GetGxObject(JArray array, String CmpContext, bool IsMasterPage)
282-
{
283-
try
284-
{
285-
JObject obj;
282+
{
283+
try
284+
{
285+
JObject obj;
286+
string paramCmpContext = CmpContext ?? string.Empty;
287+
string paramIsMasterPage = IsMasterPage.ToString();
288+
286289
for (int i = 0; i < array.Count; i++)
287-
{
290+
{
288291
obj = array.GetObject(i);
289-
string objCmpContext = obj["CmpContext"]?.ToString();
290-
string objIsMasterPage = obj["IsMasterPage"]?.ToString();
291-
// A missing/null/empty CmpContext on the array entry is equivalent to a null-or-empty parameter.
292-
bool cmpContextMatches = string.IsNullOrEmpty(objCmpContext)
293-
? string.IsNullOrEmpty(CmpContext)
294-
: objCmpContext.Equals(CmpContext);
295-
// A missing IsMasterPage on the array entry is treated as the default value (false).
296-
bool isMasterPageMatches = string.IsNullOrEmpty(objIsMasterPage)
297-
? !IsMasterPage
298-
: objIsMasterPage.Equals(IsMasterPage.ToString(), StringComparison.OrdinalIgnoreCase);
299-
if (cmpContextMatches && isMasterPageMatches)
300-
{
301-
return obj;
302-
}
303-
}
304-
obj = new JObject();
305-
obj.Put("CmpContext", CmpContext);
306-
obj.Put("IsMasterPage", IsMasterPage.ToString());
292+
string objCmpContext = obj["CmpContext"]?.ToString() ?? string.Empty;
293+
string objIsMasterPage = obj["IsMasterPage"]?.ToString() ?? string.Empty;
294+
295+
if (objCmpContext.Equals(paramCmpContext) && objIsMasterPage.Equals(paramIsMasterPage))
296+
{
297+
return obj;
298+
}
299+
}
300+
301+
obj = new JObject();
302+
obj.Put("CmpContext", CmpContext);
303+
obj.Put("IsMasterPage", IsMasterPage.ToString());
307304
array.Add(obj);
308-
return obj;
309-
}
305+
return obj;
306+
}
310307
catch (Exception ex)
311308
{
312309
GXLogging.Error(log, "GetGxObject error", ex);
313310
}
314311

315312
return null;
316-
}
313+
}
317314

318315
public void ajax_rsp_assign_attri(String CmpContext, bool IsMasterPage, String AttName, Object AttValue)
319316
{

0 commit comments

Comments
 (0)