@@ -85,6 +85,39 @@ public void arrayFieldIndexAndParentTags() {
8585 Assert .assertEquals ("data-cslp=ct.e1.en-us.items" , dollar .getString ("items" ));
8686 }
8787
88+ /**
89+ * Parent field tag for an array must use the field-level metakey (for variant resolution), not the last
90+ * element's {@code _metadata.uid} suffix — otherwise a per-element variant key (e.g. {@code items.uidB})
91+ * would incorrectly win for the parent {@code items} tag.
92+ */
93+ @ Test
94+ public void arrayFieldParentTagUsesFieldMetakeyNotLastElementMetadata () {
95+ JSONObject applied = new JSONObject ();
96+ applied .put ("items" , "fieldVar" );
97+ applied .put ("items.uidB" , "wrongVar" );
98+ JSONObject metaA = new JSONObject ();
99+ metaA .put ("uid" , "uidA" );
100+ JSONObject metaB = new JSONObject ();
101+ metaB .put ("uid" , "uidB" );
102+ JSONObject el0 = new JSONObject ();
103+ el0 .put ("_metadata" , metaA );
104+ el0 .put ("x" , "a" );
105+ JSONObject el1 = new JSONObject ();
106+ el1 .put ("_metadata" , metaB );
107+ el1 .put ("x" , "b" );
108+ JSONArray arr = new JSONArray ().put (el0 ).put (el1 );
109+ JSONObject entry = new JSONObject ();
110+ entry .put ("uid" , "e1" );
111+ entry .put ("_applied_variants" , applied );
112+ entry .put ("items" , arr );
113+ Utils .addEditableTags (entry , "ct" , false , "en-us" , null );
114+ String parentItemsTag = entry .getJSONObject ("$" ).getString ("items" );
115+ Assert .assertTrue ("parent field should resolve variant via key \" items\" " ,
116+ parentItemsTag .contains ("ct.e1_fieldVar.en-us.items" ));
117+ Assert .assertFalse ("parent field must not apply last element's variant (items.uidB -> wrongVar)" ,
118+ parentItemsTag .contains ("e1_wrongVar" ));
119+ }
120+
88121 @ Test
89122 public void referenceInArrayUsesRefPrefix () {
90123 JSONObject ref = new JSONObject ();
@@ -99,6 +132,33 @@ public void referenceInArrayUsesRefPrefix() {
99132 Assert .assertEquals ("data-cslp=author_ct.refuid.en-us.title" , refDollar .getString ("title" ));
100133 }
101134
135+ /**
136+ * Referenced entry may declare its own {@code locale}; recursive {@code getTag} must receive {@code refLocale}
137+ * (not the parent entry locale) so nested plain objects use the correct path segment, and nested refs in arrays
138+ * without {@code locale} fall back to that reference locale (not the top-level entry locale).
139+ */
140+ @ Test
141+ public void referenceInArrayPassesRefLocaleToNestedGetTag () {
142+ JSONObject nested = new JSONObject ();
143+ nested .put ("name" , "Nested" );
144+ JSONObject subRef = new JSONObject ();
145+ subRef .put ("_content_type_uid" , "child_ct" );
146+ subRef .put ("uid" , "c1" );
147+ subRef .put ("x" , "v" );
148+ JSONObject ref = new JSONObject ();
149+ ref .put ("_content_type_uid" , "author_ct" );
150+ ref .put ("uid" , "refuid" );
151+ ref .put ("locale" , "fr-fr" );
152+ ref .put ("profile" , nested );
153+ ref .put ("nested_refs" , new JSONArray ().put (subRef ));
154+ JSONObject entry = new JSONObject ();
155+ entry .put ("uid" , "e1" );
156+ entry .put ("authors" , new JSONArray ().put (ref ));
157+ Utils .addEditableTags (entry , "post" , false , "en-us" , null );
158+ Assert .assertEquals ("data-cslp=author_ct.refuid.fr-fr.profile.name" , nested .getJSONObject ("$" ).getString ("name" ));
159+ Assert .assertEquals ("data-cslp=child_ct.c1.fr-fr.x" , subRef .getJSONObject ("$" ).getString ("x" ));
160+ }
161+
102162 @ Test
103163 public void variantDirectFieldAppendsVariantToUidSegment () {
104164 JSONObject applied = new JSONObject ();
0 commit comments