Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Fix error in TextDescriptorReader when data contains leading empty spaces #691

Merged
merged 1 commit into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/profiles/device-description/DeviceDescription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class TextDescriptorReader
while (mReadPoint < mValEnd && isspace(*mReadPoint))
mReadPoint++;

mFieldEnd = val;
mFieldEnd = mReadPoint;

Version = (mReadPoint < mValEnd) ? *mReadPoint : 0;
Key = 0;
Expand Down
12 changes: 12 additions & 0 deletions src/test-apps/TestDeviceDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ void TestTextDecoding(void)
const char *textDevDesc1 = "1S:01AA01AB5011003W$";
const char *textDevDesc2 = "1V:235A$P:1$R:1$D:140914$S:05BA01AC0313003G$L:18B43000000A91B3$W:18B43001D183$I:TOPAZZZ-91B3$C:07KP74$";
const char *textDevDesc3 = "1V:235A$P:13$R:1$D:160805$S:15AA01ZZ01160101$E:18B4300400000101$";
const char *textDevDesc4 = " 1V:E100$P:13$R:1$D:160805$S:15AA01ZZ01160101$E:18B4300400000101$";

devDesc.Clear();
WeaveDeviceDescriptor::DecodeText(textDevDesc1, strlen(textDevDesc1), devDesc);
Expand Down Expand Up @@ -127,6 +128,17 @@ void TestTextDecoding(void)
AssertValue(devDesc.ManufacturingDate.Month, 8);
AssertValue(devDesc.ManufacturingDate.Day, 5);
AssertValue(devDesc.DeviceId, 0x18B4300400000101UL);

devDesc.Clear();
WeaveDeviceDescriptor::DecodeText(textDevDesc3, strlen(textDevDesc3), devDesc);
AssertValue(devDesc.VendorId, kWeaveVendor_Google);
AssertValue(devDesc.ProductId, 0x0013);
AssertValue(devDesc.ProductRevision, 1);
AssertValue(devDesc.SerialNumber, "15AA01ZZ01160101");
AssertValue(devDesc.ManufacturingDate.Year, 2016);
AssertValue(devDesc.ManufacturingDate.Month, 8);
AssertValue(devDesc.ManufacturingDate.Day, 5);
AssertValue(devDesc.DeviceId, 0x18B4300400000101UL);
}

void TestTextEncoding(void)
Expand Down