Skip to content

Replace Windows-reserved characters in test fixture filenames with URL encoding#31

Merged
nielstron merged 9 commits intomainfrom
copilot/refactor-unittest-file-names
Dec 9, 2025
Merged

Replace Windows-reserved characters in test fixture filenames with URL encoding#31
nielstron merged 9 commits intomainfrom
copilot/refactor-unittest-file-names

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 9, 2025

Test fixture files contained ? and & in filenames to represent HTTP query parameters, preventing repository checkout on Windows where these are reserved characters.

Changes

  • Test fixtures: Renamed 12 files using URL encoding scheme:

    • ?___ (query separator)
    • &%26 (URL-encoded)

    Example: GetInverterRealtimeData.cgi?Scope=Device&DeviceId=0GetInverterRealtimeData.cgi___Scope=Device%26DeviceId=0

  • Mock server: Updated translate_path() to URL-encode query strings after unquoting incoming requests:

    # Before: Simple string replacement (vulnerable to injection)
    path = path.replace("?", "___").replace("&", "__")
    
    # After: Proper URL encoding (secure)
    path = urllib.parse.unquote(path)  # Standard HTTP behavior
    if "?" in path:
        base, query = path.split("?", 1)
        path = f"{base}___{urllib.parse.quote(query, safe='=')}"

This prevents crafted URLs like /api___param=value from bypassing the encoding to access unintended test fixtures.

  • CI/CD: Updated GitHub Actions workflow:
    • Added Windows (Python 3.12) to the test matrix to verify Windows compatibility
    • Added continue-on-error: true to coveralls upload step to prevent workflow failures when the service is unavailable

Testing

  • ✅ All 31 tests pass on Ubuntu (Python 3.8-3.13)
  • ✅ Tests will run on Windows (Python 3.12) in CI to verify compatibility
  • ✅ No Windows-reserved characters in filenames
  • ✅ Security verified: crafted URLs cannot access unintended files
  • ✅ Coveralls upload failures won't block the workflow
Original prompt

This section details on the original issue you should resolve

<issue_title>No checkout on Windows possible - Question marks in unittest files</issue_title>
<issue_description>Hi,

right now, it is not possible to develop, test or use the repository on Windows (11).

The cloning itself works, but the main branch cannot be checked out, it fails with Clone succeeded, but checkout failed.

This is due to the question marks in the unittest files, e.g., pyfronius\tests\test_structure\v0\solar_api\GetInverterRealtimeData.cgi?Scope=Device&DeviceIndex=1&DataCollection=CommonInverterData

A question mark is a reserved character on Windows that cannot be contained in paths (see e.g., here or more generally here).

Would it be possible to refactor them?

Thanks in advance! 🙂 </issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 9, 2025 16:27
- Replace question marks (?) with triple underscores (___) in test filenames
- Replace ampersands (&) with double underscores (__) in test filenames
- Update fronius_mock_server.py to translate URL query parameters to new filename format
- All tests pass successfully with the new naming scheme

Co-authored-by: nielstron <20638630+nielstron@users.noreply.github.com>
- Replace simple __ replacement with proper URL encoding (%26 for &)
- This prevents security issues where crafted URLs with __ could access files
- URL-encoding is Windows-safe and prevents ambiguous filename mappings
- All 31 tests pass successfully

Co-authored-by: nielstron <20638630+nielstron@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor unittest file names to remove reserved characters Replace Windows-reserved characters in test fixture filenames with URL encoding Dec 9, 2025
Copilot AI requested a review from nielstron December 9, 2025 16:35
Copy link
Copy Markdown
Owner

@nielstron nielstron left a comment

Choose a reason for hiding this comment

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

LGTM

@nielstron
Copy link
Copy Markdown
Owner

@copilot two things

  1. make sure that a coveralls upload error in the CI does not fail the workflow
  2. add windows runs to the execution matrix (just one python version) to make sure it really works on windows

- Add Windows (Python 3.12) to the test matrix to verify Windows compatibility
- Add continue-on-error to coveralls upload step to prevent workflow failures
- This ensures the workflow doesn't fail if coveralls service is unavailable

Co-authored-by: nielstron <20638630+nielstron@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Dec 9, 2025

@copilot two things

  1. make sure that a coveralls upload error in the CI does not fail the workflow
  2. add windows runs to the execution matrix (just one python version) to make sure it really works...

Done in commit a2776f8:

  1. Added continue-on-error: true to the coveralls upload step to prevent workflow failures
  2. Added Windows (Python 3.12) to the test matrix alongside all existing Ubuntu/Python combinations

@socket-security
Copy link
Copy Markdown

socket-security bot commented Dec 9, 2025

@nielstron nielstron marked this pull request as ready for review December 9, 2025 17:22
@nielstron nielstron merged commit de19fde into main Dec 9, 2025
28 checks passed
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.

No checkout on Windows possible - Question marks in unittest files

2 participants