8000 Java: Add new quality query to detect `String#replaceAll` with non-regex first argument by owen-mc · Pull Request #19115 · github/codeql · GitHub
[go: up one dir, main page]

Skip to content

Java: Add new quality query to detect String#replaceAll with non-regex first argument #19115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix punctuation
  • Loading branch information
owen-mc committed Apr 10, 2025
commit 626a7d50074befe1092981198c7ca7d8d67ac310
2 changes: 1 addition & 1 deletion java/ql/src/Performance/StringReplaceAllWithNonRegex.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ public class Test {
## References

- Java SE Documentation: [String.replaceAll](https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/lang/String.html#replaceAll(java.lang.String,java.lang.String)).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor. I don't see String.replaceAll mentioned at all in the link provided. This seems to link to the String class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should go to the replaceAll method in the page on the String class. It seems to work for me.

- Common Weakness Enumeration: [CWE-1176](https://cwe.mitre.org/data/definitions/1176.html)
- Common Weakness Enumeration: [CWE-1176](https://cwe.mitre.org/data/definitions/1176.html).
2 changes: 1 addition & 1 deletion java/ql/src/Performance/StringReplaceAllWithNonRegex.ql
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ where
//only contains characters that could be a simple string
firstArg.getValue().regexpMatch("^[a-zA-Z0-9]+$")
select replaceAllCall,
"This call to 'replaceAll' should be a call `replace` as its $@ is not a regular expression.",
"This call to 'replaceAll' should be a call to 'replace' as its $@ is not a regular expression.",
firstArg, "first argument"
0