Skip to content

Commit 15e9837

Browse files
committed
revert back to use aws_byte_cursor_find_exact
1 parent ec85193 commit 15e9837

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

source/mqtt_iot_metrics.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,15 @@ static int s_parse_delimited_entries(
101101
struct aws_uri_param entry_param;
102102
AWS_ZERO_STRUCT(entry_param);
103103

104+
/* Use a copy to avoid modifying entry_cursor which tracks iteration state */
105+
struct aws_byte_cursor working_cursor = entry_cursor;
104106
struct aws_byte_cursor equals_pos;
105-
if (aws_byte_cursor_find_exact(&entry_cursor, &equals_delim, &equals_pos) == AWS_OP_SUCCESS) {
106-
entry_param.key.ptr = entry_cursor.ptr;
107-
entry_param.key.len = equals_pos.ptr - entry_cursor.ptr;
108-
entry_param.value = aws_byte_cursor_advance(&entry_cursor, entry_param.key.len + 1);
107+
if (aws_byte_cursor_find_exact(&working_cursor, &equals_delim, &equals_pos) == AWS_OP_SUCCESS) {
108+
size_t equals_offset = equals_pos.ptr - working_cursor.ptr;
109+
entry_param.key = aws_byte_cursor_advance(&working_cursor, equals_offset);
110+
/* Skip the "=" delimiter */
111+
aws_byte_cursor_advance(&working_cursor, 1);
112+
entry_param.value = working_cursor;
109113
} else {
110114
/* No equals sign, treat entire entry as key */
111115
entry_param.key = entry_cursor;

tests/shared_utils_tests.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -573,16 +573,18 @@ static int s_test_mqtt_append_sdk_metrics_existing_metadata(struct aws_allocator
573573

574574
/* Username already contains SDK, Platform, and Metadata fields */
575575
struct aws_byte_cursor original_username = aws_byte_cursor_from_c_str(
576-
"testuser?SDK=ExistingSDK&Platform=ExistingPlatform&Metadata=(ExistingKey=ExistingValue)");
576+
"testuser?SDK=ExistingSDK&Platform=ExistingPlatform&Metadata=(ExistingKey1=ExistingValue1;ExistingKey2="
577+
"ExistingValue2)");
577578

578579
ASSERT_SUCCESS(
579580
aws_mqtt_append_sdk_metrics_to_username(allocator, &original_username, &metrics, &output_username, NULL));
580581

581582
struct aws_byte_cursor output_cursor = aws_byte_cursor_from_buf(&output_username);
582583

583-
/* Verify the output contains merged metadata: (ExistingKey=ExistingValue;NewKey=NewValue) */
584-
struct aws_byte_cursor merged_metadata =
585-
aws_byte_cursor_from_c_str("Metadata=(ExistingKey=ExistingValue;NewKey=NewValue)");
584+
/* Verify the output contains merged metadata:
585+
* ((ExistingKey1=ExistingValue1;ExistingKey2=ExistingValue2;NewKey=NewValue) */
586+
struct aws_byte_cursor merged_metadata = aws_byte_cursor_from_c_str(
587+
"Metadata=(ExistingKey1=ExistingValue1;ExistingKey2=ExistingValue2;NewKey=NewValue)");
586588
struct aws_byte_cursor found;
587589

588590
ASSERT_SUCCESS(aws_byte_cursor_find_exact(&output_cursor, &merged_metadata, &found));

0 commit comments

Comments
 (0)