Skip to content
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

Check string length before joining #1421

Merged
merged 1 commit into from Oct 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/brakeman/processors/lib/call_conversion_helper.rb
Expand Up @@ -19,16 +19,17 @@ def join_arrays lhs, rhs, original_exp = nil
end
end

STRING_LENGTH_LIMIT = 50

# Join two string literals into one.
def join_strings lhs, rhs, original_exp = nil
if string? lhs and string? rhs
result = Sexp.new(:str).line(lhs.line)
result.value = lhs.value + rhs.value

if result.value.length > 50
if (lhs.value.length + rhs.value.length > STRING_LENGTH_LIMIT)
# Avoid gigantic strings
lhs
else
result = Sexp.new(:str).line(lhs.line)
result.value = lhs.value + rhs.value
result
end
elsif call? lhs and lhs.method == :+ and string? lhs.first_arg and string? rhs
Expand Down