Skip to content

Commit af6dd2e

Browse files
committed
Merge branch 'fix-brakeman-audit-failures' of github.com:fiveNinePlusR/pbm
2 parents fc8ff4d + 5d17168 commit af6dd2e

19 files changed

+178
-32
lines changed

app/controllers/api/v1/location_machine_xrefs_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ def create
3838

3939
return return_response(AUTH_REQUIRED_MSG, 'errors') if user.nil?
4040

41-
location_id = params[:location_id]
42-
machine_id = params[:machine_id]
41+
location_id = params[:location_id].to_i
42+
machine_id = params[:machine_id].to_i
4343
condition = params[:condition]
4444
status_code = 200
4545

46-
return return_response('Failed to find machine', 'errors') if machine_id.nil? || location_id.nil? || !Machine.exists?(machine_id) || !Location.exists?(location_id)
46+
return return_response('Failed to find machine', 'errors') if machine_id.zero? || location_id.zero? || !Machine.exists?(machine_id) || !Location.exists?(location_id)
4747

4848
lmx = LocationMachineXref.find_by_location_id_and_machine_id(location_id, machine_id)
4949

app/controllers/api/v1/location_picture_xrefs_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def show
2121
def create
2222
return return_response(AUTH_REQUIRED_MSG, 'errors') if current_user.nil?
2323

24-
location_id = params[:location_id]
25-
return return_response('Failed to find location', 'errors') if location_id.nil? || !Location.exists?(location_id)
24+
location_id = params[:location_id].to_i
25+
return return_response('Failed to find location', 'errors') if location_id.zero? || !Location.exists?(location_id)
2626

2727
photo = params[:photo]
2828
return return_response('Missing photo to add', 'errors') if photo.nil?

app/controllers/machines_controller.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ def autocomplete
2828
sanitized_sql = ActiveRecord::Base.sanitize_sql_array([sql, { term: params[:term] }])
2929

3030
results = ActiveRecord::Base.connection.select_all(sanitized_sql)
31-
.map do |m|
32-
name_year = "#{m['name']} (#{m['manufacturer']}, #{m['year']})"
31+
.map do |m|
32+
name_year = "#{m['name']} (#{m['manufacturer']}, #{m['year']})"
3333

34-
{ label: name_year, value: name_year, id: m['id'], group_id: m['machine_group_id'] }
35-
end
34+
{ label: name_year, value: name_year, id: m['id'], group_id: m['machine_group_id'] }
35+
end
3636

3737
end
3838

app/controllers/pages_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def map
5252

5353
params[:user_faved] = user.id if user && !params[:user_faved].blank?
5454

55-
if !params[:by_location_id].blank? && loc = Location.where(id: params[:by_location_id]).first
55+
if !params[:by_location_id].blank? && (loc = Location.where(id: params[:by_location_id]).first)
5656
@title_params[:title] = loc.name
5757
location_type = loc.location_type.name + ' - ' unless loc.location_type.nil?
5858
machine_list = ' - ' + loc.machine_names_first_no_year.join(', ') unless loc.machine_names_first_no_year.empty?
@@ -74,7 +74,7 @@ def region
7474
@location_count = @locations.count
7575
@lmx_count = @region.machines_count
7676

77-
if !params[:by_location_id].blank? && loc = Location.where(id: params[:by_location_id]).first
77+
if !params[:by_location_id].blank? && (loc = Location.where(id: params[:by_location_id]).first)
7878
@title_params[:title] = loc.name
7979
location_type = loc.location_type.name + ' - ' unless loc.location_type.nil?
8080
machine_list = ' - ' + loc.machine_names_first_no_year.join(', ') unless loc.machine_names_first_no_year.empty?

app/models/location.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ class Location < ApplicationRecord
33

44
validates_presence_of :name, :street, :city, :country
55
validates :phone, phone: { possible: true, allow_blank: true, message: 'Phone format not valid.' }
6-
validates :website, format: { with: %r{http(s?)://}, message: 'must begin with http:// or https://' }, if: :website?
7-
validates :name, :street, :city, format: { with: /^\S.*/, message: "Can't start with a blank", multiline: true }
6+
validates :website, format: { with: %r{\Ahttp(s?)://}, message: 'must begin with http:// or https://' }, if: :website?
7+
validates :name, :street, :city, format: { with: /\A\S.*/, message: "Can't start with a blank", multiline: true }
88
validates :lat, :lon, presence: { message: 'Latitude/Longitude failed to generate. Please double check address and try again, or manually enter the lat/lon' }
99

1010
belongs_to :location_type, optional: true

app/models/machine_score_xref.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ class MachineScoreXref < ApplicationRecord
88

99
scope :zone_id, lambda { |id|
1010
joins(:location_machine_xref).joins(:location).where("
11-
locations.zone_id = #{id}
12-
")
11+
locations.zone_id = ?
12+
", id)
1313
}
1414

1515
scope :region, lambda { |name|
1616
r = Region.find_by_name(name.downcase)
1717
joins(:location_machine_xref).joins(:location).where("
1818
location_machine_xrefs.id = machine_score_xrefs.location_machine_xref_id
1919
and locations.id = location_machine_xrefs.location_id
20-
and locations.region_id = #{r.id}
21-
")
20+
and locations.region_id = ?
21+
", r.id)
2222
}
2323

2424
def username

app/models/suggested_location.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ class SuggestedLocation < ApplicationRecord
55
validates_presence_of :name, :machines, on: :create
66
validates_presence_of :street, :city, :zip, on: :update
77

8-
validates :website, format: { with: %r{http(s?)://}, message: 'must begin with http:// or https://' }, if: :website?, on: :update
9-
validates :name, :street, :city, format: { with: /^\S.*/, message: "Can't start with a blank", multiline: true }, on: :update
8+
validates :website, format: { with: %r{\Ahttp(s?)://}, message: 'must begin with http:// or https://' }, if: :website?, on: :update
9+
validates :name, :street, :city, format: { with: /\A\S.*/, message: "Can't start with a blank", multiline: true }, on: :update
1010
validates :lat, :lon, presence: { message: 'Latitude/Longitude failed to generate. Please double check address and try again, or manually enter the lat/lon' }, on: :update
1111

1212
belongs_to :region, optional: true
@@ -97,19 +97,21 @@ def convert_to_location(user_email)
9797

9898
delete
9999

100-
ActiveRecord::Base.connection.execute(<<HERE)
100+
sql = <<HERE
101101
insert into versions values (
102102
nextval('versions_id_seq'),
103103
'Location',
104-
#{location.id},
104+
:location_id,
105105
'converted from suggested location',
106-
'#{user_email}',
106+
:user_email,
107107
NULL,
108108
now(),
109109
NULL,
110110
NULL
111111
)
112112
HERE
113+
sanitized_sql = ActiveRecord::Base.sanitize_sql_array([sql, { location_id: location.id, user_email: user_email }])
114+
ActiveRecord::Base.connection.execute(sanitized_sql)
113115
end
114116
end
115117
end

app/models/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class User < ApplicationRecord
1111

1212
validates :username, presence: true, uniqueness: { case_sensitive: false }
1313

14-
validates_format_of :username, with: /^[a-zA-Z0-9_\.]*$/, multiline: true
14+
validates_format_of :username, with: /\A[a-zA-Z0-9_\.]*\z/, multiline: true
1515
validates :username, length: { maximum: 20 }
1616
strip_attributes only: %i[username password]
1717

app/views/locations/_form.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
:javascript
3333
$(function () {
3434
$('#by_#{key}_name').autocomplete({
35-
source: '/#{key}s/autocomplete?region_level_search=1;region=#{params[:region]}',
35+
source: '/#{key}s/autocomplete?region_level_search=1;region=#{h(params[:region])}',
3636
minLength: 2,
3737
delay: 500
3838
});

app/views/locations/_locations.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[#{[@lat, @lon].join(', ')}]
1616
);
1717

18-
var hrefOrig = '#{request.scheme}://#{request.host_with_port}/#{@region ? @region.name.downcase : @operators_map ? @operators_map : "map"}?';
18+
var hrefOrig = '#{request.scheme}://#{request.host_with_port}/#{@region ? h(@region.name.downcase) : @operators_map ? @operators_map : "map"}?';
1919
var def_value = window.location.href;
2020

2121
var url = '';

0 commit comments

Comments
 (0)