Skip to content

Commit

Permalink
Validate input of comments, without null character
Browse files Browse the repository at this point in the history
This prevents the creation of a comment with the null character, that
would make the comment invalid for xml output.

Co-authored-by: Victor Pereira <vpereira@suse.com>
  • Loading branch information
eduardoj and vpereira committed Sep 18, 2018
1 parent 76f9212 commit 8b19a36
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/api/app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Comment < ApplicationRecord
validates :body, :commentable, :user, presence: true
# FIXME: this probably should be MEDIUMTEXT(16MB) instead of text (64KB)
validates :body, length: { maximum: 65_535 }
validates :body, format: { with: /\A[^\u0000]*\Z/,
message: 'must not contain null characters' }

validate :validate_parent_id

Expand Down

0 comments on commit 8b19a36

Please sign in to comment.