by drdec · 4y ago · 0 comments
ResultSet rs = DB."SELECT * FROM Person p WHERE p.last_name = \{name}";
This when it becomes valid java will not allow an SQL injection attack. The name part would be properly passed as a parameter. Not a string concatenation. Per https://openjdk.org/jeps/430
If that was not the example you where thinking about, sorry :)
Otherwise yes don't build parameterized SQL out of strings !
So DB."SELECT * FROM Person p WHERE p.last_name = \{name}" would basically be a function call like DB("SELECT * FROM Person p WHERE p.last_name = ", name), which would do the right thing to parameterize the SQL.
It doesn't. That's not a plain string replacement...
Second, the author was using that as an example of Java showing a pattern of adding syntax improvements, which again might be something that maintains popularity.
Finally, from the article:
But let's talk about the Java we have today, not the one coming in 6 months.
It was just one talking point. Did you even read the article?- use a library that implements RFC 5322 properly.
- don't validate the email address (that is, don't try to reject most invalid addresses) and just check that the field contains at least one `@` to be sure the user didn't enter something else than his email address by accident.
Tying to perform email address validation with regex you're writing yourself is the best way to reject perfectly acceptable email address and get frustrated users.
https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va...
The format for emails is surprisingly complex, and while you can use a regex to catch 99% of the right values, it's very difficult to get it 100% right. Often the best thing to do is just to try and send an email to the address a validation link.
Check that its a string containing '@' with at least one character before and after the @ symbol is usually the only sensible thing to do.
This is exactly what the regex in the example is doing.