Skip to content

fix: URL-encode item hrefs to handle spaces in filenames - #26

Open
Dodothereal wants to merge 1 commit into
NewGraphEnvironment:mainfrom
Dodothereal:fix/25-url-encode-item-hrefs-with-spaces-in-col
Open

fix: URL-encode item hrefs to handle spaces in filenames#26
Dodothereal wants to merge 1 commit into
NewGraphEnvironment:mainfrom
Dodothereal:fix/25-url-encode-item-hrefs-with-spaces-in-col

Conversation

@Dodothereal

Copy link
Copy Markdown

fix: URL-encode item hrefs to handle spaces in filenames

URL-encode item hrefs with spaces in collection and item self-links

Fixes URL encoding issues for item hrefs that contain spaces in their filenames. This addresses the issue where GeoTIFF files with spaces in their names (like "bc_082e003_xli1m_utm11_2018 (2).tif") were causing problems with STAC item href generation.

Changes Made

  1. Modified scripts/item_create.py to properly encode item hrefs using the existing encode_url_for_gdal function:

    • Set the item's self-href to the URL-encoded version after saving the item JSON
    • Updated the duplicate detection logic to compare encoded hrefs when checking for existing items in the collection
    • Return the encoded href from the process_item function for use in the main loop
  2. Updated the duplicate prevention logic in the main function:

    • Encode existing item hrefs when building the set for duplicate detection
    • Use the encoded href returned from process_item when checking for duplicates

Implementation Details

  • Used the existing encode_url_for_gdal function which properly URL-encodes spaces as %20
  • Applied encoding consistently to both new items being added and existing items when checking for duplicates
  • Avoided double-encoding by only encoding hrefs that weren't already encoded
  • Leveraged the existing utility function that's already imported and used elsewhere in the codebase

Testing

Verified the changes by:

  • Confirming the code compiles successfully: python3 -m py_compile scripts/item_create.py
  • Verifying imports work correctly: python3 -c "import scripts.item_create; print('Import successful')"
  • Reviewing the logic to ensure proper handling of both encoded and non-encoded URLs

The changes are minimal and focused, reusing existing utility functions to ensure consistency with the rest of the codebase.

Fixes #25

AI assistance disclosure

This contribution was produced by an autonomous AI coding agent (Claude Code) that @Dodothereal operates and monitors. @Dodothereal is accountable for it, will address review feedback promptly, and will close this PR immediately if this kind of contribution is unwelcome in this project. Commits carry an Assisted-by: Claude Code trailer.

- Encode item self-hrefs using encode_url_for_gdal to properly handle spaces
- Update duplicate detection to use encoded hrefs for consistency
- Fixes issue NewGraphEnvironment#25: URL-encode item hrefs with spaces in collection and item self-links
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.

URL-encode item hrefs with spaces in collection and item self-links

1 participant