4
0
Эх сурвалжийг харах

fix(text): improve base64 regex

- Avoid warning: invalid escape sequence '\/'
- ensure full string matches
- ensure correct number of fill characters
Jason Rumney 7 сар өмнө
parent
commit
f295d8ffdf

+ 3 - 1
custom_components/tuya_local/text.py

@@ -60,7 +60,9 @@ class TuyaLocalText(TuyaLocalEntity, TextEntity):
         if self._value_dp.rawtype == "hex":
         if self._value_dp.rawtype == "hex":
             self._attr_pattern = "[0-9a-fA-F]*"
             self._attr_pattern = "[0-9a-fA-F]*"
         elif self._value_dp.rawtype == "base64":
         elif self._value_dp.rawtype == "base64":
-            self._attr_pattern = "[-A-Za-z0-9+\/]*={0,3}"
+            self._attr_pattern = (
+                "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$"
+            )
         # TODO: general pattern support
         # TODO: general pattern support
 
 
         if hasattr(self, "_attr_pattern"):
         if hasattr(self, "_attr_pattern"):