dharple / detox

Tames problematic filenames
BSD 3-Clause "New" or "Revised" License
332 stars 19 forks source link

OneDrive .tbl file #104

Open bordenc opened 1 year ago

bordenc commented 1 year ago

I took some time to rewrite safe.tbl to strict OneDrive support and would like to share it with others.

Problem: OneDrive (and, by extension, NTFS) forbids a handful of characters, causing syncs to fail. Although safe.tbl strips these characters out, I wanted something that would only strip out the absolute bare minimum because I'm working on client files, not my own, so I want to disrupt the files as little as possible.

Solution (in diff format):

52d51
< 
84,85c83,86
< 0x23          '#'
< 0x25          %
---
> 0x20          ' '     # space
> 0x21          !
> 0x24          $
> 0x27          "'"
89a91
> 0x3b          ;
90a93
> 0x40          @
92a96
> 0x60          `
96a101
> # Source: https://support.microsoft.com/en-us/office/restrictions-and-limitations-in-onedrive-and-sharepoint-64883a5d-228e-48f5-b3d2-eb39e07630fa#invalidcharacters
102,103d106
< 0x20          _       # space
< 0x21          _       # !
105,106c108,110
< 0x24          _       # $
< 0x27          _       # '
---
> 0x23          #       # # supported in new accounts after 2017
> 0x25          %       # % supported in new accounts after 2017
> 0x26          &       # & unsupported only in Office 2010
110d113
< 0x3b          _       # ;
114d116
< 0x40          _       # @
116d117
< 0x60          _       # `
123,134c124,129
< 0x28          -       # (
< 0x29          -       # )
< 0x5b          -       # [
< 0x5d          -       # ]
< 0x7b          -       # {
< 0x7d          -       # }
< 
< #
< # Other
< #
< 
< 0x26          _and_   # &
---
> 0x28          (       # (
> 0x29          )       # )
> 0x5b          [       # [
> 0x5d          ]       # ]
> 0x7b          {       # {
> 0x7d          }       # }

I hope this helps other users and saves them troubleshooting. I might also be able to provide some feedback on the manpages because I found that I had to do quite a bit of trial-and-error to get this to work. Feedback welcome if my code stinks, which it usually does.

dharple commented 7 months ago

I'm not sure which version of safe.tbl you're patching against. Can you provide me with the base version, via detox -V, or just attach the entire file? I'm happy to include the table with the distributed code for others to use.

dharple commented 7 months ago

You're also welcome to submit a pull request, if you'd like.

bordenc commented 6 months ago

I'm not a very good programmer, so I'm likely to botch a PR. Nevertheless, here's my configuration:

sequence default {
#        utf_8;
        safe {
            filename "/home/me/scripts/detox/onedrive.tbl";
        };
#        wipeup;
};

and onedrive.tbl (although ntfs.tbl would probably be more appropriate):

# This file is part of the Detox package.
#
# Copyright (c) Doug Harple <detox.dharple@gmail.com>
#
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.

start

#
# Alphanumeric
#

0x30        0
0x31        1
0x32        2
0x33        3
0x34        4
0x35        5
0x36        6
0x37        7
0x38        8
0x39        9

0x41        A
0x42        B
0x43        C
0x44        D
0x45        E
0x46        F
0x47        G
0x48        H
0x49        I
0x4a        J
0x4b        K
0x4c        L
0x4d        M
0x4e        N
0x4f        O
0x50        P
0x51        Q
0x52        R
0x53        S
0x54        T
0x55        U
0x56        V
0x57        W
0x58        X
0x59        Y
0x5a        Z

0x61        a
0x62        b
0x63        c
0x64        d
0x65        e
0x66        f
0x67        g
0x68        h
0x69        i
0x6a        j
0x6b        k
0x6c        l
0x6d        m
0x6e        n
0x6f        o
0x70        p
0x71        q
0x72        r
0x73        s
0x74        t
0x75        u
0x76        v
0x77        w
0x78        x
0x79        y
0x7a        z

#
# Chars to leave alone
#

0x20        ' ' # space
0x21        !
0x24        $
0x27        "'"
0x2b        +
0x2c        ,
0x2d        -
0x2e        .
0x3b        ;
0x3d        =
0x40        @
0x5e        ^
0x5f        _
0x60        `
0x7e        ~

#
# Chars to translate to _
# Source: https://support.microsoft.com/en-us/office/restrictions-and-limitations-in-onedrive-and-sharepoint-64883a5d-228e-48f5-b3d2-eb39e07630fa#invalidcharacters
#

0x09        ' ' # tab
0x0A        ' ' # new line
0x0D        ' ' # carriage return
0x22        "'" # "
0x23        #   # # supported in new accounts after 2017
0x25        %   # % supported in new accounts after 2017
0x26        &   # & unsupported only in Office 2010
0x2a        _   # *
0x2f        _   # /
0x3a        ;   # :
0x3c        _   # <
0x3e        _   # >
0x3f        _   # ?
0x5c        _   # \
0x7c        _   # |

#
# Chars to translate to -
#

0x28        (   # (
0x29        )   # )
0x5b        [   # [
0x5d        ]   # ]
0x7b        {   # {
0x7d        }   # }

end

I hope that helps