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

PathFilter questions #313

Closed
q3cpma opened this issue Oct 23, 2018 · 4 comments · Fixed by #324
Closed

PathFilter questions #313

q3cpma opened this issue Oct 23, 2018 · 4 comments · Fixed by #324
Labels
Accepted Accepted issue on our roadmap Feature New feature Needed: documentation Documentation is required Needed: tests Tests are required Priority: medium Medium priority Status: in progress Issue/pull request which is currently being worked on Stretch Optional goal for the current sprint (may not be delivered)
Milestone

Comments

@q3cpma
Copy link

q3cpma commented Oct 23, 2018

Hello,

as a POSIX OS user, I'm wondering about the forced character stripping in paths, and am confused at the PathFilter class in path.py:

  • What are these "separators" (: and |) and why are they stripped?
  • Same for "special" characters, since fat is already here.

I'm thinking about replacing everything but quotes by "POSIX" and "vfat", while having a configuration option for adding an additional string of characters to replace and maybe another for the fallback character.

@MerlijnWajer
Copy link
Collaborator

This looks weird indeed. The unicode quoting code is also something we can get rid of, I think.

@q3cpma
Copy link
Author

q3cpma commented Oct 23, 2018 via email

@MerlijnWajer
Copy link
Collaborator

I think you can use sys.platform for that

@JoeLametta
Copy link
Collaborator

@q3cpma Let me quote you to have the diff formatted in a code block:

diff --git a/whipper/common/path.py b/whipper/common/path.py
index a5d0eb4..2b0fba9 100644
--- a/whipper/common/path.py
+++ b/whipper/common/path.py
@@ -21,47 +21,24 @@
 import re


+POSIX = 0
+MACOS = 1
+WINDOWS = 2
+
 class PathFilter(object):
     """
     I filter path components for safe storage on file systems.
     """

-    def __init__(self, slashes=True, quotes=True, fat=True, special=False):
+    def __init__(self, os=POSIX):
         """
-        @param slashes: whether to convert slashes to dashes
-        @param quotes:  whether to normalize quotes
-        @param fat:     whether to strip characters illegal on FAT filesystems
-        @param special: whether to strip special characters
+        @param os: the path character set restrictions to use
         """
-        self._slashes = slashes
-        self._quotes = quotes
-        self._fat = fat
-        self._special = special
+        self._os = os

     def filter(self, path):
-        if self._slashes:
-            path = re.sub(r'[/\\]', '-', path, re.UNICODE)
-
-        def separators(path):
-            # replace separators with a space-hyphen or hyphen
-            path = re.sub(r'[:]', ' -', path, re.UNICODE)
-            path = re.sub(r'[\|]', '-', path, re.UNICODE)
-            return path
-
-        # change all fancy single/double quotes to normal quotes
-        if self._quotes:
-            path = re.sub(ur'[\xc2\xb4\u2018\u2019\u201b]', "'", path,
-                          re.UNICODE)
-            path = re.sub(ur'[\u201c\u201d\u201f]', '"', path, re.UNICODE)
-
-        if self._special:
-            path = separators(path)
-            path = re.sub(r'[\*\?&!\'\"\$\(\)`{}\[\]<>]',
-                          '_', path, re.UNICODE)
-
-        if self._fat:
-            path = separators(path)
-            # : and | already gone, but leave them here for reference
-            path = re.sub(r'[:\*\?"<>|"]', '_', path, re.UNICODE)
-
-        return path
+        if self._os == POSIX or self._os == MACOS:
+            repl = r'/'
+        else:
+            repl = r'[/\\:*?"<>|]'
+        return re.sub(repl, '_', path, re.UNICODE)

@JoeLametta JoeLametta added Status: in progress Issue/pull request which is currently being worked on Accepted Accepted issue on our roadmap Priority: medium Medium priority Feature New feature Needed: tests Tests are required Needed: documentation Documentation is required Stretch Optional goal for the current sprint (may not be delivered) labels Nov 12, 2018
@JoeLametta JoeLametta added this to the 2.0 milestone Nov 13, 2018
JoeLametta added a commit that referenced this issue Feb 22, 2020
Added new filter options.

Fixes #313.

Signed-off-by: JoeLametta <JoeLametta@users.noreply.github.com>
JoeLametta added a commit that referenced this issue Feb 22, 2020
Added new filter options.

Fixes #313.

Signed-off-by: JoeLametta <JoeLametta@users.noreply.github.com>
JoeLametta added a commit that referenced this issue Feb 22, 2020
Added new filter options.

Fixes #313.

Signed-off-by: JoeLametta <JoeLametta@users.noreply.github.com>
JoeLametta added a commit that referenced this issue Feb 22, 2020
Added filter options:
- dot (replace leading dot with _)
- posix (replace illegal chars in *nix OSes with _)
- vfat (replace illegal chars in VFAT filesystems with _)
- whitespace (replace all whitespace chars with _)
- printable (replace all non printable ASCII chars with _)

Removed filter options:
- fat (replaced with vfat)
- special

Fixes #313.

Signed-off-by: JoeLametta <JoeLametta@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Accepted issue on our roadmap Feature New feature Needed: documentation Documentation is required Needed: tests Tests are required Priority: medium Medium priority Status: in progress Issue/pull request which is currently being worked on Stretch Optional goal for the current sprint (may not be delivered)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants