Skip to content

Commit

Permalink
clear base64 prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
omohokcoj committed Sep 2, 2024
1 parent b16322d commit 92909ce
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/submitters/normalize_values.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module Submitters
module NormalizeValues
CHECKSUM_CACHE_STORE = ActiveSupport::Cache::MemoryStore.new

BASE64_PREFIX_REGEXP = %r{\Adata:image/\w+;base64,}

BaseError = Class.new(StandardError)

UnknownFieldName = Class.new(BaseError)
Expand Down Expand Up @@ -134,7 +136,8 @@ def find_or_build_attachment(value, type, account, for_submitter = nil)
find_or_create_blob_from_url(account, value)
elsif type.in?(%w[signature initials]) && value.length < 60
find_or_create_blob_from_text(account, value, type)
elsif (data = Base64.decode64(value)) && Marcel::MimeType.for(data).include?('image')
elsif (data = Base64.decode64(value.sub(BASE64_PREFIX_REGEXP, ''))) &&
Marcel::MimeType.for(data).include?('image')
find_or_create_blob_from_base64(account, data, type)
else
raise InvalidDefaultValue, "Invalid value, url, base64 or text < 60 chars is expected: #{value.first(200)}..."
Expand Down

0 comments on commit 92909ce

Please sign in to comment.