Skip to content

Commit

Permalink
handled presence of non printable char in the validator response
Browse files Browse the repository at this point in the history
Signed-off-by: Vanessa Fotso <[email protected]>
  • Loading branch information
vanessuniq committed Aug 25, 2024
1 parent d29d43a commit 78a0a07
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions lib/inferno/dsl/fhir_resource_validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,12 @@ def operation_outcome_from_hl7_wrapped_response(response_hash)

# @private
def operation_outcome_from_validator_response(response, runnable)
operation_outcome_from_hl7_wrapped_response(JSON.parse(response.body))
# Sanitize the response body by removing non-printable/control characters
sanitized_body = response.body.gsub(/[^[:print:]\r\n]+/, '')

operation_outcome_from_hl7_wrapped_response(JSON.parse(sanitized_body))
rescue JSON::ParserError
runnable.add_message('error', "Validator Response: HTTP #{response.status}\n#{response.body}")
runnable.add_message('error', "Validator Response: HTTP #{response.status}\n#{sanitized_body}")
raise Inferno::Exceptions::ErrorInValidatorException,
'Validator response was an unexpected format. '\
'Review Messages tab or validator service logs for more information.'
Expand Down
7 changes: 5 additions & 2 deletions lib/inferno/dsl/fhir_validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,12 @@ def call_validator(resource, profile_url)

# @private
def operation_outcome_from_validator_response(response, runnable)
FHIR::OperationOutcome.new(JSON.parse(response.body))
# Sanitize the response body by removing non-printable/control characters
sanitized_body = response.body.gsub(/[^[:print:]\r\n]+/, '')

FHIR::OperationOutcome.new(JSON.parse(sanitized_body))
rescue JSON::ParserError
runnable.add_message('error', "Validator Response: HTTP #{response.status}\n#{response.body}")
runnable.add_message('error', "Validator Response: HTTP #{response.status}\n#{sanitized_body}")
raise Inferno::Exceptions::ErrorInValidatorException,
'Validator response was an unexpected format. '\
'Review Messages tab or validator service logs for more information.'
Expand Down

0 comments on commit 78a0a07

Please sign in to comment.