Repository: paperless-ngx/paperless-ngx

Issue:
[Other] Name of downloaded File contains (escaping?) character '+'
I am currently experiencing the following behaviour after migrating to ng-x 1.6.0.

When downloaded, a file contains the following special charater (i reckon as a safe-escaping char?) 

> 2019-07-30+Allianz+Ihre+betriebliche+Krankenversicherung+(bKV)+AK-9874071796.pdf

Until 1.5.0 it was the following
> 2019-07-30 Allianz Ihre betriebliche Krankenversicherung (bKV) AK-9874071796.pdf

The naming of the document is as follows

> Ihre betriebliche Krankenversicherung (bKV) AK-9874071796

Following settings was provided before and after the migration:

> PAPERLESS_FILENAME_FORMAT={created_year}/{correspondent}/{document_type}-{title}-{created_year}-{created_month}

I am not sure if this is a bug, or desired behaviour. Can anyone provide further information or is experiencing the same issue?
Ignore .stversions folder (from syncthing)
### Discussed in https://github.com/paperless-ngx/paperless-ngx/discussions/302

<div type='discussions-op-text'>

<sup>Originally posted by **nothingmn** March 13, 2022</sup>
Hello,

I have my documents kept in sync across multiple machines using syncthing.  When Im using the backup feature of syncthing it creates a folder .stversions.  I would prefer this folder be ignored in paperless-ngx, since they are older versions of the same file.

</div>


This would update the ignore patterns with more sensible defaults:

```
.stversions
.localized
.DS_Store
desktop.ini
```

Should be added like `.stfolder` is done now, including tests and documentation:

https://github.com/paperless-ngx/paperless-ngx/search?q=stfolder&type=


Discussion:
When we create a sanitized filename for download, `-` is actually used to replace any invalid characters.  However, that filename doesn't appear to have anything invalid in it.  And it shouldn't be `+` that I know of either.

If you view the document from the admin site (Admin -> Documents -> this document), what is the filename it says there?
Here the current Values. The sanitized name was working in 1.5.0 pretty sure about that. 

![image](https://user-images.githubusercontent.com/88422038/159551326-1bf65055-cf87-4519-86cb-97083fc48fe5.png)

![image](https://user-images.githubusercontent.com/88422038/159551521-b193aa10-01da-40a6-af41-f6bdf328b5bd.png)

Thank you.  I haven't actually downloaded files except through the exporter.  Is this through the API (`/api/documents/<pk>/download/`) or is there a location in the UI where you're downloading from?
I used this button in the document-details

![image](https://user-images.githubusercontent.com/88422038/159629374-88cd3ffd-1a03-44f8-8f45-e3e3f4f86755.png)

Havent tried the exporter or api yet. 
> The sanitized name was working in 1.5.0 pretty sure about that.

This may have been introduced in #57, which was included in 1.6.0
We probably should be using `quote`, not `quote_plus`.

https://docs.python.org/3/library/urllib.parse.html#url-quoting


Resolving patch:
diff --git a/src/documents/views.py b/src/documents/views.py
--- a/src/documents/views.py
+++ b/src/documents/views.py
@@ -6,7 +6,7 @@
 from datetime import datetime
 from time import mktime
 from unicodedata import normalize
-from urllib.parse import quote_plus
+from urllib.parse import quote
 
 from django.conf import settings
 from django.db.models import Case
@@ -244,7 +244,7 @@ def file_response(self, pk, request, disposition):
         # RFC 5987 addresses this issue
         # see https://datatracker.ietf.org/doc/html/rfc5987#section-4.2
         filename_normalized = normalize("NFKD", filename).encode("ascii", "ignore")
-        filename_encoded = quote_plus(filename)
+        filename_encoded = quote(filename)
         content_disposition = (
             f"{disposition}; "
             f'filename="{filename_normalized}"; '
diff --git a/src/paperless/settings.py b/src/paperless/settings.py
--- a/src/paperless/settings.py
+++ b/src/paperless/settings.py
@@ -455,7 +455,7 @@ def default_threads_per_worker(task_workers):
     json.loads(
         os.getenv(
             "PAPERLESS_CONSUMER_IGNORE_PATTERNS",
-            '[".DS_STORE/*", "._*", ".stfolder/*"]',
+            '[".DS_STORE/*", "._*", ".stfolder/*", ".stversions/*", ".localized/*", "desktop.ini"]',
         ),
     ),
 )


Test patch: