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

Commit

Permalink
Merge pull request #691 from mburshteyn1/textdescriptorreader-fix
Browse files Browse the repository at this point in the history
Fix error in TextDescriptorReader when data contains leading empty spaces
  • Loading branch information
robszewczyk authored Aug 10, 2022
2 parents d7619d9 + 9bf1d6f commit e3c8ca3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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

0 comments on commit e3c8ca3

Please sign in to comment.