Skip to content

Commit

Permalink
Trim blanks and invisible characters from property value for discover…
Browse files Browse the repository at this point in the history
…y. Add thing discovery match test with blank and invisible characters. (#836)

Signed-off-by: Pierre GAUFILLET <[email protected]>
  • Loading branch information
pgaufillet authored May 25, 2024
1 parent b1af980 commit c88196d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private synchronized void readDiscoveryProperties() throws IOException {
continue;
}

newProperties.add(new RequiredProperty(discoveryElement[0].trim(), unescape(discoveryElement[1].trim())));
newProperties.add(new RequiredProperty(discoveryElement[0].trim(), unescape(discoveryElement[1]).trim()));
}

if (newProperties.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ xiaomi_lumisensormagnet,modelId=lumi.sensor_magnet
xiaomi_lumiremotemini,modelId=lumi.remote.b1acn01
innr-rc-110,vendor=innr,modelId=RC 110
osram-switch-4x-eu,vendor=OSRAM,modelId=Switch 4x EU-LIGHTIFY
legrand_dimmer_without_neutral,vendor=\u001f Legrand,modelId=\u001f Dimmer switch w/o neutral
legrand_dimmer_without_neutral,vendor=Legrand,modelId=Dimmer switch w/o neutral
tuya_ts0041,modelId=TS0041
tuya_ts0042,modelId=TS0042
tuya_ts0043,modelId=TS0043
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,11 @@ public void testMatcher()
properties = new HashMap<>();
properties.put(Thing.PROPERTY_VENDOR, "Vendor3");
assertEquals(null, matcher.matchThingType(properties));

// Match with invisible characters
properties = new HashMap<>();
properties.put(Thing.PROPERTY_VENDOR, "Vendor4");
properties.put(Thing.PROPERTY_MODEL_ID, "Model3");
assertEquals(new ThingTypeUID("zigbee:type5"), matcher.matchThingType(properties));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ type1,vendor=Vendor1,modelId=Model1
type2,vendor=Vendor2,modelId=Model2
type3,vendor=Vendor1,modelId=Model2
type4,vendor=Vendor1,modelId=Model2,firmwareVersion=Version4
type5,vendor=\u001F Vendor4,modelId= Model3\u001F

0 comments on commit c88196d

Please sign in to comment.