Skip to content

Commit 93955f6

Browse files
Merge pull request livecode#2774 from livecodeali/bugfix-15798
[[ Bug 15798 ]] Resolve references to array properties in variables properly
2 parents 7d37e45 + 999b3f3 commit 93955f6

File tree

2 files changed

+48
-20
lines changed

2 files changed

+48
-20
lines changed

docs/notes/bugfix-15798.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Array property references in variables not resolved properly

engine/src/property.cpp

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,10 @@ bool MCProperty::resolveprop(MCExecContext& ctxt, Properties& r_which, MCNameRef
12251225
// customprop is non-nil. Handle this case here rather than in the caller to
12261226
// simplify code.
12271227
if (which == P_CUSTOM)
1228-
/* UNCHECKED */ MCNameClone(customprop, t_prop_name);
1228+
{
1229+
if (!MCNameClone(customprop, t_prop_name))
1230+
return false;
1231+
}
12291232

12301233
// At present, something like the 'pVar[pIndex] of me' is evaluated as 'the pVar of me'
12311234
// this is because any index is extracted from the pVar variable. It might be worth
@@ -1237,39 +1240,63 @@ bool MCProperty::resolveprop(MCExecContext& ctxt, Properties& r_which, MCNameRef
12371240
if (!ctxt . EvalExprAsStringRef(destvar, EE_PROPERTY_BADEXPRESSION, &t_string))
12381241
return false;
12391242

1240-
MCScriptPoint sp(*t_string);
1243+
// AL-2015-08-27: [[ Bug 15798 ]] Parse into index and property name before determining
1244+
// if this is a custom property or not (otherwise things like textStyle["bold"] are
1245+
// interpreted as custom properties).
1246+
MCAutoStringRef t_icarray, t_property_name;
1247+
uindex_t t_offset, t_end_offset;
1248+
// SN-2014-08-08: [[ Bug 13135 ]] Targetting a custom var should resolve the index AND suppress
1249+
// it from the initial name
1250+
if (MCStringFirstIndexOfChar(*t_string, '[', 0, kMCStringOptionCompareExact, t_offset) &&
1251+
MCStringLastIndexOfChar(*t_string, ']', UINDEX_MAX, kMCStringOptionCompareExact, t_end_offset) &&
1252+
t_end_offset == MCStringGetLength(*t_string) - 1)
1253+
{
1254+
if (!MCStringCopySubstring(*t_string, MCRangeMake(0, t_offset), &t_property_name))
1255+
return false;
1256+
1257+
// AL-2015-08-27: [[ Bug 15798 ]] If the index is quoted, we don't want to include the
1258+
// quotes in the index name.
1259+
if (MCStringGetCodepointAtIndex(*t_string, t_offset + 1) == '"' &&
1260+
MCStringGetCodepointAtIndex(*t_string, t_end_offset - 1) == '"')
1261+
{
1262+
t_offset++;
1263+
t_end_offset--;
1264+
}
1265+
1266+
if (!MCStringCopySubstring(*t_string, MCRangeMake(t_offset + 1, t_end_offset - t_offset - 1), &t_icarray))
1267+
return false;
1268+
}
1269+
else
1270+
t_property_name = *t_string;
1271+
1272+
if (*t_icarray != nil)
1273+
{
1274+
if (!MCNameCreate(*t_icarray, t_index_name))
1275+
return false;
1276+
}
1277+
1278+
MCScriptPoint sp(*t_property_name);
12411279
Symbol_type type;
12421280
const LT *te;
12431281
if (sp.next(type) && sp.lookup(SP_FACTOR, te) == PS_NORMAL && te->type == TT_PROPERTY && sp.next(type) == PS_EOF)
12441282
t_prop = (Properties)te -> which;
12451283
else
1246-
{
1247-
MCAutoStringRef t_icarray, t_property_name;
1248-
uindex_t t_offset;
1249-
// SN-2014-08-08: [[ Bug 13135 ]] Targetting a custom var should resolve the index AND suppress
1250-
// it from the initial name
1251-
if (MCStringFirstIndexOfChar(*t_string, '[', 0, kMCStringOptionCompareExact, t_offset))
1252-
{
1253-
MCStringCopySubstring(*t_string, MCRangeMake(t_offset + 1, MCStringGetLength(*t_string) - t_offset - 2), &t_icarray);
1254-
MCStringCopySubstring(*t_string, MCRangeMake(0, t_offset), &t_property_name);
1255-
}
1256-
else
1257-
t_property_name = *t_string;
1258-
1284+
{
12591285
// MW-2011-09-02: [[ Bug 9698 ]] Always create a name for the property, otherwise
12601286
// if the var contains empty, this function returns a nil name which causes
12611287
// customprop to be used incorrectly.
12621288
//
1263-
/* UNCHECKED */ MCNameCreate(*t_property_name, t_prop_name);
1264-
1265-
if (*t_icarray != nil)
1266-
/* UNCHECKED */ MCNameCreate(*t_icarray, t_index_name);
1289+
if (!MCNameCreate(*t_property_name, t_prop_name))
1290+
return false;
12671291

12681292
t_prop = P_CUSTOM;
12691293
}
12701294
}
12711295
else if (customindex != nil)
1272-
/* UNCHECKED */ ctxt . EvalExprAsNameRef(customindex, EE_PROPERTY_BADEXPRESSION, t_index_name);
1296+
{
1297+
if (!ctxt . EvalExprAsNameRef(customindex, EE_PROPERTY_BADEXPRESSION, t_index_name))
1298+
return false;
1299+
}
12731300

12741301
r_which = t_prop;
12751302
r_prop_name = t_prop_name;

0 commit comments

Comments
 (0)