File tree Expand file tree Collapse file tree 1 file changed +3
-13
lines changed
docs/Secure-Coding-Guide-for-Python/CWE-707/CWE-175 Expand file tree Collapse file tree 1 file changed +3
-13
lines changed Original file line number Diff line number Diff line change @@ -149,30 +149,20 @@ ORIGINAL_NUMBER = 12.345 # This will read as 12,345 in German
149149
150150
151151def compare_number (number ):
152- input_number = locale.atof(input (" Enter a number: " ))
152+ input_number = locale.atof(input (f " Enter a number { ORIGINAL_NUMBER } : " ))
153153 # Test if inputted number equals current number
154154 return number == input_number
155155
156156
157157print (f " Locale is { locale.getlocale()} " )
158- print (f " Do the numbers match? { compare_number(ORIGINAL_NUMBER )} " )
159-
160- # Console output:
161- # Locale is ('English_Ireland', '1252')
162- # Enter a number: 12,345
163- # Do the numbers match? False
164158
165- # After setting the locale
159+ print ( f " Do the numbers match? { compare_number( ORIGINAL_NUMBER ) } " )
166160
161+ # Setting the locale to German
167162locale.setlocale(locale.LC_ALL , ' de_DE.utf8' )
168163print (f " Locale is { locale.getlocale()} " )
169164print (f " Do the numbers match? { compare_number(ORIGINAL_NUMBER )} " )
170165
171- # Console output:
172- # Locale is ('de_DE', 'UTF-8')
173- # Enter a number: 12,345
174- # Do the numbers match? True
175-
176166```
177167
178168## Non-Compliant Code Example (Encoding)
You can’t perform that action at this time.
0 commit comments