Challenge: Preventing Code Injection
Tarefa
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.
Solução
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 1. Capítulo 5
single
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Awesome!
Completion rate improved to 5.56
Challenge: Preventing Code Injection
Deslize para mostrar o menu
Tarefa
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.
Solução
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 1. Capítulo 5
single