Challenge: Preventing Code Injection
Swipe to start coding
Refactor a function that previously used eval() to perform mathematical operations based on a string input, so that it cannot be exploited for code injection. Use only a dictionary of explicitly allowed operations.
- Only allow the operations "add", "subtract", "multiply", and "divide".
- For each allowed operation, perform the corresponding arithmetic on
aandb. - If an operation is not allowed, return
None. - For division, if
bis zero, returnNone.
Lösung
Danke für Ihr Feedback!
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Can you explain this in simpler terms?
What are some examples related to this topic?
Where can I learn more about this?
Awesome!
Completion rate improved to 5.56
Challenge: Preventing Code Injection
Swipe um das Menü anzuzeigen
Swipe to start coding
Refactor a function that previously used eval() to perform mathematical operations based on a string input, so that it cannot be exploited for code injection. Use only a dictionary of explicitly allowed operations.
- Only allow the operations "add", "subtract", "multiply", and "divide".
- For each allowed operation, perform the corresponding arithmetic on
aandb. - If an operation is not allowed, return
None. - For division, if
bis zero, returnNone.
Lösung
Danke für Ihr Feedback!
single