▲ | nhumrich 9 days ago | |||||||
Yes. Only if your dev remembers to use sanatized all the time. This is how most SQL works today. You could also forget and accidentally write a f-string, or because you dont know. But with t-strings you can actually prevent unsanatized inputs. With your example, you need to intentionally sanitize still. You cant throw an error on unsanitized because the language has no way to know if its sanitized or not. Either way, its just a string. "returning an f-string" is equivalent to returning a normal string at runtime. | ||||||||
▲ | ratorx 9 days ago | parent | next [-] | |||||||
Well you enforce this with types. That’s how every other language does it. By specifying that the type of the function has to be a sanitised string, it will reject unsanitised string with the type checker. > it has no way of knowing if it’s sanitised or not It does. You define the SanitisedString class. Constructing one sanitises the string. Then when you specify that as the argument, it forces the user to sanitise the string. If you want to do it without types, you can check with `isinstance` at runtime, but that is not as safe. | ||||||||
| ||||||||
▲ | stefan_ 9 days ago | parent | prev [-] | |||||||
No, most SQL today uses placeholders and has since circa 2008. If you are sanitizing you are doing it wrong to begin with. |