Skip to content

Fix data uri normalization bug#118

Merged
RogerPodacter merged 2 commits into
evm-backend-demofrom
fix_data_uri
Oct 13, 2025
Merged

Fix data uri normalization bug#118
RogerPodacter merged 2 commits into
evm-backend-demofrom
fix_data_uri

Conversation

@RogerPodacter

@RogerPodacter RogerPodacter commented Oct 13, 2025

Copy link
Copy Markdown
Member

Note

Handle data:,{...} JSON payloads in protocol extractors and add the facet_rails_common gem.

  • Extractors:
    • CollectionsParamsExtractor and GenericProtocolExtractor: support raw JSON data:,{...} URIs by bypassing DataUri decoding for this form.
    • GenericProtocolExtractor#valid_data_uri?: allow data:,{...} as valid.
  • Dependencies:
    • Add facet_rails_common (via Git) and its dependency order_query in Gemfile.lock.

Written by Cursor Bugbot for commit 3922db3. This will update automatically on new commits. Configure here.

@RogerPodacter RogerPodacter requested a review from Copilot October 13, 2025 18:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug in data URI normalization by standardizing the handling of data URIs that lack an explicit MIME type. The fix ensures that data URIs starting with "data:," are normalized to "data:text/plain," during initialization rather than being handled as special cases in individual methods.

  • Adds input validation to reject non-string arguments
  • Normalizes "data:," URIs to "data:text/plain," before regex matching
  • Simplifies mimetype and data methods by removing special case handling

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread lib/data_uri.rb Outdated
return 'text/plain'
end

match[:mimetype]

Copilot AI Oct 13, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mimetype method should handle cases where match[:mimetype] is nil or empty. Without the previous fallback logic, this could return nil instead of the expected 'text/plain' default.

Suggested change
match[:mimetype]
mt = match[:mimetype]
mt.nil? || mt.empty? ? 'text/plain' : mt

Copilot uses AI. Check for mistakes.
Comment thread lib/data_uri.rb Outdated
Comment on lines +22 to +24
if normalized_uri.start_with?("data:,")
normalized_uri = normalized_uri.sub("data:,", "data:text/plain,")
end

Copilot AI Oct 13, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The normalization only handles the exact case 'data:,' but should also handle variations with whitespace or parameters like 'data: ,' or 'data:;base64,'. Consider using a more robust pattern match.

Suggested change
if normalized_uri.start_with?("data:,")
normalized_uri = normalized_uri.sub("data:,", "data:text/plain,")
end
# Normalize any data URI with empty mediatype (with optional whitespace/parameters) to data:text/plain,
normalized_uri = normalized_uri.sub(/\Adata:(\s*(;[a-zA-Z0-9\-]+=[^;,]*)*)?,/, "data:text/plain,")

Copilot uses AI. Check for mistakes.
cursor[bot]

This comment was marked as outdated.

return false unless DataUri.valid?(uri)

return true if uri.start_with?("data:,{")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Data URI Validation Order Issue

In valid_data_uri?, the DataUri.valid?(uri) check occurs before the special case for data:,{...} URIs. This order means URIs intended for the special handling will likely fail the initial DataUri.valid? check, preventing the dedicated extraction logic from being reached.

Fix in Cursor Fix in Web

@RogerPodacter RogerPodacter merged commit 623256c into evm-backend-demo Oct 13, 2025
2 checks passed
@RogerPodacter RogerPodacter deleted the fix_data_uri branch October 13, 2025 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants