File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -95,19 +95,20 @@ def parse_dict_string(string: str, separator: str = ";"):
9595
9696def add_px (value ):
9797 """
98- Append 'px' to numeric values (int, float, or numeric strings ).
99- Leaves values with units or non-numeric strings unchanged.
98+ Append 'px' only if the value is purely numeric (int, float, or numeric string ).
99+ If there is any non-numeric character, return the original value unchanged.
100100 """
101101 if isinstance (value , (int , float )):
102102 return f"{ value } px"
103103
104104 if isinstance (value , str ):
105105 stripped = value .strip ()
106- try :
107- float (stripped )
106+
107+ # Check if it's a valid number (integer or float)
108+ if stripped .replace ("." , "" , 1 ).isdigit ():
108109 return f"{ stripped } px"
109- except ValueError :
110- return value
110+
111+ return value
111112
112113 return value
113114
You can’t perform that action at this time.
0 commit comments