Skip to content

Conversation

@Vein05
Copy link
Collaborator

@Vein05 Vein05 commented Apr 17, 2025

Issue: url.ParseRequestURI() incorrectly handles absolute file paths as valid URLs

Problem
When using url.ParseRequestURI() to validate URLs for image processing, the function incorrectly returns success (nil error) for absolute file paths (e.g., /usr/local/images/photo.jpg) because it considers them valid URI paths according to RFC 3986. This caused the code to attempt downloading local files as if they were web URLs.

Impact

  • Local file paths were being mistakenly treated as web URLs
  • Unnecessary HTTP requests were being made for local files
  • Failed image processing when using absolute paths

Solution
Replace the url.ParseRequestURI() check with an explicit HTTP(S) prefix check:

Technical Details

  • The URI specification (RFC 3986) considers absolute paths starting with "/" as valid URI paths
  • url.ParseRequestURI() follows this specification, making it unsuitable for distinguishing between web URLs and file paths
  • Using strings.HasPrefix() provides a more explicit and accurate way to identify web URLs

Testing

Resolves: #54

@Vein05 Vein05 self-assigned this Apr 17, 2025
@Vein05 Vein05 merged commit 2d563f7 into main Apr 17, 2025
1 check failed
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.

Image url bugs for absolute paths

1 participant