@@ -112,6 +112,27 @@ addValue(
112112 return LDBooleanTrue ;
113113}
114114
115+ static const char *
116+ LDi_getBucketAttribute (const struct LDJSON * const obj )
117+ {
118+ const struct LDJSON * bucketBy ;
119+
120+ LD_ASSERT (obj );
121+ LD_ASSERT (LDJSONGetType (obj ) == LDObject );
122+
123+ bucketBy = LDObjectLookup (obj , "bucketBy" );
124+
125+ if (!LDi_notNull (bucketBy )) {
126+ return "key" ;
127+ }
128+
129+ if (LDJSONGetType (bucketBy ) != LDText ) {
130+ return NULL ;
131+ }
132+
133+ return LDGetText (bucketBy );
134+ }
135+
115136EvalStatus
116137LDi_evaluate (
117138 struct LDClient * const client ,
@@ -914,19 +935,18 @@ LDi_segmentRuleMatchUser(
914935
915936 {
916937 float bucket ;
938+ const char * attribute ;
917939
918- const struct LDJSON * const bucketBy =
919- LDObjectLookup (segmentRule , "bucketBy" );
920-
921- const char * const attribute =
922- LDi_notNull (bucketBy ) ? LDGetText (bucketBy ) : "key" ;
940+ attribute = LDi_getBucketAttribute (segmentRule );
923941
924- if (! LDi_bucketUser ( user , segmentKey , attribute , salt , & bucket ) ) {
925- LD_LOG (LD_LOG_ERROR , "LDi_bucketUser error " );
942+ if (attribute == NULL ) {
943+ LD_LOG (LD_LOG_ERROR , "failed to parse bucketBy " );
926944
927- return EVAL_MEM ;
945+ return EVAL_SCHEMA ;
928946 }
929947
948+ LDi_bucketUser (user , segmentKey , attribute , salt , & bucket );
949+
930950 if (bucket < LDGetNumber (weight ) / 100000 ) {
931951 return EVAL_MATCH ;
932952 } else {
@@ -1127,6 +1147,7 @@ LDi_bucketUser(
11271147 LD_ASSERT (bucket );
11281148
11291149 attributeValue = NULL ;
1150+ * bucket = 0 ;
11301151
11311152 if ((attributeValue = LDi_valueOfAttribute (user , attribute ))) {
11321153 char raw [256 ], bucketableBuffer [256 ];
@@ -1261,10 +1282,18 @@ LDi_variationIndexForUser(
12611282 variation = LDGetIter (variations );
12621283 LD_ASSERT (variation );
12631284
1264- if (! LDi_bucketUser ( user , key , "key" , salt , & userBucket )) {
1265- LD_LOG ( LD_LOG_ERROR , "failed to bucket user" ) ;
1285+ {
1286+ const char * attribute ;
12661287
1267- return LDBooleanFalse ;
1288+ attribute = LDi_getBucketAttribute (rollout );
1289+
1290+ if (attribute == NULL ) {
1291+ LD_LOG (LD_LOG_ERROR , "failed to parse bucketBy" );
1292+
1293+ return LDBooleanFalse ;
1294+ }
1295+
1296+ LDi_bucketUser (user , key , attribute , salt , & userBucket );
12681297 }
12691298
12701299 for (; variation ; variation = LDIterNext (variation )) {
0 commit comments