From f56da9c7519f3e117986b91b6106f7d64d2036b7 Mon Sep 17 00:00:00 2001 From: Max Wofford Date: Mon, 9 Jun 2025 18:25:48 -0400 Subject: [PATCH] Filter out null bytes in process commit job Fix #300 --- app/jobs/process_commit_job.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/jobs/process_commit_job.rb b/app/jobs/process_commit_job.rb index 38809fd..ccf8cb5 100644 --- a/app/jobs/process_commit_job.rb +++ b/app/jobs/process_commit_job.rb @@ -83,7 +83,7 @@ class ProcessCommitJob < ApplicationJob commit = Commit.find_or_create_by(sha: api_commit_sha) do |c| c.user_id = user.id c.repository_id = repository&.id - c.github_raw = commit_data_json + c.github_raw = sanitize_json_data(commit_data_json) c.created_at = commit_actual_created_at c.updated_at = Time.current end @@ -119,4 +119,13 @@ class ProcessCommitJob < ApplicationJob Rails.logger.error "[ProcessCommitJob] Validation failed for commit #{commit_sha} (User ##{user.id}): #{e.message}" end end + + def sanitize_json_data(data) + json_string = data.to_json + sanitized_string = json_string.gsub(/\\u0000/, "") + JSON.parse(sanitized_string) + rescue JSON::ParserError => e + Rails.logger.warn "[ProcessCommitJob] Failed to sanitize JSON data: #{e.message}. Falling back to original data." + data + end end