Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filenames with square brackets ignored #348

Closed
kwbr opened this issue Feb 4, 2024 · 2 comments
Closed

Filenames with square brackets ignored #348

kwbr opened this issue Feb 4, 2024 · 2 comments
Labels

Comments

@kwbr
Copy link

kwbr commented Feb 4, 2024

Describe the bug
When using the extension filter, filenames with square brackets are not correctly echoed:

$ ls Downloads/*.opus
'Downloads/hello [world].opus'
$ organize run test.yaml
Config: "test.yaml"

⚙ Rule #0: Upload mixes ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
/home/kai/Downloads
  ./hello .opus
    - (echo) /home/kai/Downloads/hello .opus

success 1 / fail 0

The path is correctly used for example in shell actions but the output is misleading.

Interestingly these test passes:

def test_echo_path_with_spaces(fs, testoutput):
    make_files(["file A.txt", "file B with [brackets].txt"], "test")
    Config.from_string(
        """
        rules:
          - locations: /test
            actions:
              - echo: "{path}"
        """
    ).execute(simulate=False, output=testoutput)
    assert Counter(testoutput.messages) == Counter(["/test/file A.txt", "/test/file B with [brackets].txt"])
    
def test_filename_with_spaces(fs, testoutput):
    files = {
        "test file with spaces.jpg": "",
        "test file with [brackets].jpg": "",
    }
    make_files(files, "test")
    config = """
        test_ext: &test
            - jpg
        rules:
        - locations: /test
          filters:
            - extension: *test
          actions:
            - echo: 'Found file: {path}'
        """
    Config.from_string(config).execute(simulate=False, output=testoutput)
    assert testoutput.messages == [
        "Found file: /test/test file with spaces.jpg",
        "Found file: /test/test file with [brackets].jpg"
    ]

Environment (please complete the following information):

  • OS: Linux, pipx installed organize
  • Output of organize --version: organize v3.0.1

Your config file

audio_ext: &audio
  - m4a
  - mp3
  - wav
  - ogg
  - opus

rules:

  - name: "Upload mixes"
    locations:
      - ~/Downloads
    filters:
      - extension: *audio
    actions:
      - echo: "{path}"
@kwbr kwbr added the bug label Feb 4, 2024
@tfeldmann
Copy link
Owner

Thanks for reporting! Organize uses the rich library for the console output, which uses brackets for styling ([red]Some text[/]) and I totally forgot to escape file paths and messages.

The tests still work because we use output.saving.SavingOutput in the tests, which has no concept of styling.

This will be fixed in the next release!

@tfeldmann
Copy link
Owner

tfeldmann commented Feb 4, 2024

Fixed in 530c433, along with refactoring the message formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants