From 59d7721682554f5b9f456525c7d257fdb6052a91 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 25 Apr 2022 15:15:04 -0700 Subject: [PATCH] sharing: Allow double quotes in path strings Unix paths can contain double quotes. Allow entering paths with double quotes by escaping them in c-style[1] and retrieve them back properly. 1) https://httpd.apache.org/docs/2.4/expr.html Tests: Run tests on with various paths: - /var/a b - /var/c"d - /var/ef" Run the following tests. - Create a directory with the test path and create a sample file inside it. - Add a share with the test path. - Ensure that the share is accessible and the file can be downloaded. - Ensure that the list of the shares shows the path correctly. - Ensure that the share can be edited. Signed-off-by: Sunil Mohan Adapa --- actions/sharing | 6 ++++-- plinth/modules/sharing/forms.py | 5 ++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/actions/sharing b/actions/sharing index d598aeba0..1cfeb35f1 100755 --- a/actions/sharing +++ b/actions/sharing @@ -57,7 +57,7 @@ def load_augeas(): def subcommand_add(arguments): """Add a share to Apache configuration.""" name = arguments.name - path = '"' + arguments.path + '"' + path = '"' + arguments.path.replace('"', r'\"') + '"' groups = arguments.groups is_public = arguments.is_public url = '/share/' + name @@ -150,11 +150,13 @@ def _list(aug=None): url = aug.get(match + '/arg[1]') path = aug.get(match + '/arg[2]') + path = path.removesuffix('"').removeprefix('"') + path = path.replace(r'\"', '"') try: name = _get_name_from_url(url) shares.append({ 'name': name, - 'path': path.strip('"'), + 'path': path, 'url': '/share/' + name }) except ValueError: diff --git a/plinth/modules/sharing/forms.py b/plinth/modules/sharing/forms.py index cb245f4d6..b70782d12 100644 --- a/plinth/modules/sharing/forms.py +++ b/plinth/modules/sharing/forms.py @@ -20,9 +20,8 @@ class AddShareForm(forms.Form): 'A lowercase alpha-numeric string that uniquely identifies a ' 'share. Example: media.')) - path = forms.RegexField( - label=_('Path to share'), strip=True, regex=r'^[^\"]+$', - help_text=_( + path = forms.CharField( + label=_('Path to share'), strip=True, help_text=_( 'Disk path to a folder on this server that you intend to share.')) is_public = forms.BooleanField(