Skip to content

Commit 7c04247

Browse files
iHiDclaude
andauthored
Fix ArgumentError on invalid UTF-8 in tooling job output (#8474)
* Fix ArgumentError on invalid UTF-8 byte sequences in tooling job output Use .scrub before .blank? to sanitize strings from external tooling services that may contain invalid UTF-8 byte sequences. This prevents BLANK_RE regex from raising ArgumentError when matching against them. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Use safe navigation operator for .scrub to handle nil values When the JSON key doesn't exist in execution_output, the value is nil. Calling .scrub on nil raises NoMethodError. Using &.scrub allows nil to fall through to .blank? which correctly returns true for nil. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2485ded commit 7c04247

4 files changed

Lines changed: 20 additions & 3 deletions

File tree

app/commands/submission/analysis/process.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def tags_data
6969
return {} if ops_errored?
7070

7171
tags_json = tooling_job.execution_output['tags.json']
72-
return {} if tags_json.blank?
72+
return {} if tags_json&.scrub.blank?
7373

7474
res = JSON.parse(tags_json)
7575
res.is_a?(Hash) ? res.symbolize_keys : {}

app/commands/submission/representation/process.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def metadata
5656
return {} if ops_errored?
5757

5858
representation_json = tooling_job.execution_output['representation.json']
59-
return {} if representation_json.blank?
59+
return {} if representation_json&.scrub.blank?
6060

6161
res = JSON.parse(representation_json)
6262
res.is_a?(Hash) ? res.symbolize_keys : {}

app/commands/submission/test_run/process.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def results
115115
return {} if tooling_job.execution_output.nil?
116116

117117
results_json = tooling_job.execution_output['results.json']
118-
return {} if results_json.blank?
118+
return {} if results_json&.scrub.blank?
119119

120120
res = JSON.parse(results_json, allow_invalid_unicode: true)
121121
res.is_a?(Hash) ? res.symbolize_keys : {}

test/commands/submission/test_run/process_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,23 @@ class Submission::TestRun::ProcessTest < ActiveSupport::TestCase
6767
assert submission.reload.tests_exceptioned?
6868
end
6969

70+
test "handle invalid UTF-8 in results.json without raising" do
71+
submission = create :submission
72+
job = create_test_runner_job!(
73+
submission,
74+
execution_status: 200,
75+
results: { 'status' => 'pass', 'tests' => [] }
76+
)
77+
78+
invalid_bytes = "\xFF\xFE".dup.force_encoding('UTF-8')
79+
job.stubs(:execution_output).returns({ 'results.json' => invalid_bytes })
80+
81+
# This should not raise ArgumentError: invalid byte sequence in UTF-8
82+
Submission::TestRun::Process.(job)
83+
84+
assert submission.reload.tests_exceptioned?
85+
end
86+
7087
test "handle tests pass" do
7188
submission = create :submission
7289
results = { 'status' => 'pass', 'message' => "", 'tests' => [] }

0 commit comments

Comments
 (0)