mirror of
https://github.com/danieldemus/openhab-addons
synced 2026-07-31 13:34:22 +02:00
* Fix #18345, now every disallowed char will be replaced with a hyphen Signed-off-by: Marcel Goerentz <m.goerentz@t-online.de>
This commit is contained in:
+2
-1
@@ -20,6 +20,7 @@ import com.google.gson.annotations.SerializedName;
|
||||
*
|
||||
* @author Florian Hotze - Initial contribution
|
||||
* @author Luca Arnecke - Update to evcc version 0.123.1
|
||||
* @author Marcel Goerentz - Replace invalid chars with hyphens in vehicleName
|
||||
*/
|
||||
public class Loadpoint {
|
||||
// Data types from https://github.com/evcc-io/evcc/blob/master/api/api.go
|
||||
@@ -271,7 +272,7 @@ public class Loadpoint {
|
||||
* @return vehicle's title/name
|
||||
*/
|
||||
public String getVehicleName() {
|
||||
return vehicleName != null ? vehicleName.replace(":", "-") : vehicleName;
|
||||
return vehicleName != null ? vehicleName.replaceAll("[^a-zA-Z0-9_-]", "-") : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+8
-2
@@ -25,6 +25,7 @@ import com.google.gson.annotations.SerializedName;
|
||||
* @author Florian Hotze - Initial contribution
|
||||
* @author Luca Arnecke - update to evcc version 0.123.1
|
||||
* @author Daniel Kötting - update to evcc version 0.133.0
|
||||
* @author Marcel Goerentz - Replace invalid chars with hyphens in vehicles map
|
||||
*/
|
||||
public class Result {
|
||||
// Data types from https://github.com/evcc-io/evcc/blob/master/api/api.go
|
||||
@@ -224,8 +225,13 @@ public class Result {
|
||||
public Map<String, Vehicle> getVehicles() {
|
||||
Map<String, Vehicle> correctedMap = new HashMap<>();
|
||||
for (Entry<String, Vehicle> entry : vehicles.entrySet()) {
|
||||
// The key from the vehicles map is used as uid, so it should not contain semicolons.
|
||||
correctedMap.put(entry.getKey().replace(":", "-"), entry.getValue());
|
||||
// The key from the vehicles map is used as uid, so it should not contain any disallowed chars
|
||||
// If necessary replace the forbidden chars with hyphens
|
||||
String key = entry.getKey();
|
||||
if (!key.matches("[a-zA-Z0-9_-]+")) {
|
||||
key = key.replaceAll("[^a-zA-Z0-9_-]", "-");
|
||||
}
|
||||
correctedMap.put(key, entry.getValue());
|
||||
}
|
||||
return correctedMap;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user