Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 6, 2025

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.

Original prompt

Context
A corrupted commit (short SHA: a214106) introduced a malformed path under canon/01_PHYSICS where the entire document content (including newlines and Markdown) appears in the filename. This breaks navigation in the GitHub web UI and may cause local checkout failures (especially on Windows). We need to fix the repository state and add CI to prevent such filenames from being introduced in the future.

Tasks

  1. Revert the corrupted commit a214106 from main so the malformed filename is removed.
  2. Add a GitHub Actions workflow that validates filenames in new commits or PRs, failing when filenames contain control characters (including newlines), Windows-forbidden characters, trailing spaces or dots, or reserved device names.

Acceptance Criteria

  • The bad change from commit a214106 is removed from main via a PR, restoring normal navigation.
  • A new workflow exists at .github/workflows/validate-filenames.yml which blocks future malformed filenames.
  • The PR includes the workflow file as shown and explains the revert and the filename validation in the description.

Files to add

name: Validate filenames

on:
  push:
    branches: [ "main" ]
  pull_request:

jobs:
  filename-sanity:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Validate filenames
        shell: bash
        run: |
          set -euo pipefail

          # Determine changed files for this event
          if [ "${{ github.event_name }}" = "pull_request" ]; then
            BASE_SHA="${{ github.event.pull_request.base.sha }}"
            HEAD_SHA="${{ github.sha }}"
          else
            BASE_SHA="${{ github.event.before }}"
            HEAD_SHA="${{ github.sha }}"
          fi

          # Collect files we need to validate
          files="$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" || true)"
          if [ -z "$files" ]; then
            # First push or no diff available: scan entire repo
            files="$(git ls-files)"
          fi

          invalid=false

          # Check each filename
          while IFS= read -r f; do
            # Control characters (includes newline, tab, carriage return)
            if printf '%s' "$f" | grep -P '[\x00-\x1F\x7F]' >/dev/null; then
              echo "::error file=$f::Filename contains control characters (e.g., newline, tab, carriage return)."
              invalid=true
            fi

            # Windows-forbidden characters: <>:\"/\|?*
            # Note: slash (/) won't appear in a single path component but we include for completeness
            if printf '%s' "$f" | grep -E '[<>:\"\\|?*]' >/dev/null; then
              echo "::error file=$f::Filename contains characters forbidden on Windows (<>:\"\\|?*)."
              invalid=true
            fi

            base="$(basename "$f")"

            # Trailing space or trailing dot in the basename
            if printf '%s' "$base" | grep -E '[[:space:]]$|\.$' >/dev/null; then
              echo "::error file=$f::Basename ends with a space or dot, which is unsafe on Windows."
              invalid=true
            fi

            # Reserved Windows device names
            if printf '%s' "$base" | grep -E '^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\..*)?$' >/dev/null; then
              echo "::error file=$f::Basename uses a reserved Windows device name."
              invalid=true
            fi
          done <<< "$files"

          if [ "$invalid" = true ]; then
            echo "Invalid filenames detected. See errors above."
            exit 1
          fi

Implementation Notes

  • Perform a git revert of a214106 in a new branch and open a PR against main.
  • Include the new workflow file in the same PR.
  • In the PR description, clearly state that the malformed filename originated from a GitHub web editor incident and that the workflow prevents such issues going forward.

This pull request was created as a result of the following prompt from Copilot chat.

Context
A corrupted commit (short SHA: a214106) introduced a malformed path under canon/01_PHYSICS where the entire document content (including newlines and Markdown) appears in the filename. This breaks navigation in the GitHub web UI and may cause local checkout failures (especially on Windows). We need to fix the repository state and add CI to prevent such filenames from being introduced in the future.

Tasks

  1. Revert the corrupted commit a214106 from main so the malformed filename is removed.
  2. Add a GitHub Actions workflow that validates filenames in new commits or PRs, failing when filenames contain control characters (including newlines), Windows-forbidden characters, trailing spaces or dots, or reserved device names.

Acceptance Criteria

  • The bad change from commit a214106 is removed from main via a PR, restoring normal navigation.
  • A new workflow exists at .github/workflows/validate-filenames.yml which blocks future malformed filenames.
  • The PR includes the workflow file as shown and explains the revert and the filename validation in the description.

Files to add

name: Validate filenames

on:
  push:
    branches: [ "main" ]
  pull_request:

jobs:
  filename-sanity:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Validate filenames
        shell: bash
        run: |
          set -euo pipefail

          # Determine changed files for this event
          if [ "${{ github.event_name }}" = "pull_request" ]; then
            BASE_SHA="${{ github.event.pull_request.base.sha }}"
            HEAD_SHA="${{ github.sha }}"
          else
            BASE_SHA="${{ github.event.before }}"
            HEAD_SHA="${{ github.sha }}"
          fi

          # Collect files we need to validate
          files="$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" || true)"
          if [ -z "$files" ]; then
            # First push or no diff available: scan entire repo
            files="$(git ls-files)"
          fi

          invalid=false

          # Check each filename
          while IFS= read -r f; do
            # Control characters (includes newline, tab, carriage return)
            if printf '%s' "$f" | grep -P '[\x00-\x1F\x7F]' >/dev/null; then
              echo "::error file=$f::Filename contains control characters (e.g., newline, tab, carriage return)."
              invalid=true
            fi

            # Windows-forbidden characters: <>:\"/\|?*
            # Note: slash (/) won't appear in a single path component but we include for completeness
            if printf '%s' "$f" | grep -E '[<>:\"\\|?*]' >/dev/null; then
              echo "::error file=$f::Filename contains characters forbidden on Windows (<>:\"\\|?*)."
              invalid=true
            fi

            base="$(basename "$f")"

            # Trailing space or trailing dot in the basename
            if printf '%s' "$base" | grep -E '[[:space:]]$|\.$' >/dev/null; then
              echo "::error file=$f::Basename ends with a space or dot, which is unsafe on Windows."
              invalid=true
            fi

            # Reserved Windows device names
            if printf '%s' "$base" | grep -E '^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\..*)?$' >/dev/null; then
              echo "::error file=$f::Basename uses a reserved Windows device name."
              invalid=true
            fi
          done <<< "$files"

          if [ "$invalid" = true ]; then
            echo "Invalid filenames detected. See errors above."
            exit 1
          fi

Implementation Notes

  • Perform a git revert of a214106 in a new branch and open a PR against main.
  • Include the new workflow file in the same PR.
  • In the PR description, clearly state that the malformed filename originated from a GitHub web editor incident and that the workflow prevents such issues going forward.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI requested a review from ariffazil December 6, 2025 10:50
@ariffazil ariffazil marked this pull request as ready for review December 6, 2025 10:50
@ariffazil ariffazil merged commit dc3eede into main Dec 6, 2025
0 of 4 checks passed
@ariffazil ariffazil deleted the copilot/revert-corrupted-commit-a214106 branch December 6, 2025 10:51
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