mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-29 10:10:19 +00:00
tiddlywiki: Don't allow index.html as a file name
Tests: - Creating/renaming/uploading wikis with names index[.html] does not work. Doing so with other names work. Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net> [sunil: Use validators= property instead of clean_name()] Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
2cd4839c34
commit
d89fcd74f1
@ -6,12 +6,19 @@ from django.core import validators
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_not_index_file(name):
|
||||||
|
"""Validate that the normalized file name is not 'index.html'."""
|
||||||
|
if str(name) in ('index.html', 'index'):
|
||||||
|
raise forms.ValidationError(
|
||||||
|
_('Wiki files cannot be named "index.html".'))
|
||||||
|
|
||||||
|
|
||||||
class CreateWikiForm(forms.Form):
|
class CreateWikiForm(forms.Form):
|
||||||
"""Form to create a new wiki file."""
|
"""Form to create a new wiki file."""
|
||||||
|
|
||||||
name = forms.CharField(
|
name = forms.CharField(
|
||||||
label=_('Name of the wiki file, with file extension ".html"'),
|
label=_('Name of the wiki file, with file extension ".html"'),
|
||||||
strip=True, help_text=_(
|
strip=True, validators=[_validate_not_index_file], help_text=_(
|
||||||
'Wiki title and description can be set from within the wiki. '
|
'Wiki title and description can be set from within the wiki. '
|
||||||
'This file name is independent of the wiki title.'))
|
'This file name is independent of the wiki title.'))
|
||||||
|
|
||||||
@ -21,7 +28,7 @@ class RenameWikiForm(forms.Form):
|
|||||||
|
|
||||||
new_name = forms.CharField(
|
new_name = forms.CharField(
|
||||||
label=_('New name for the wiki file, with file extension ".html"'),
|
label=_('New name for the wiki file, with file extension ".html"'),
|
||||||
strip=True, help_text=_(
|
strip=True, validators=[_validate_not_index_file], help_text=_(
|
||||||
'Renaming the file has no effect on the title of the wiki.'))
|
'Renaming the file has no effect on the title of the wiki.'))
|
||||||
|
|
||||||
|
|
||||||
@ -29,9 +36,11 @@ class UploadWikiForm(forms.Form):
|
|||||||
"""Form to upload a wiki file."""
|
"""Form to upload a wiki file."""
|
||||||
|
|
||||||
file = forms.FileField(
|
file = forms.FileField(
|
||||||
label=_('A TiddlyWiki file with .html file extension'),
|
label=_('A TiddlyWiki file with .html file extension'), required=True,
|
||||||
required=True, validators=[
|
validators=[
|
||||||
validators.FileExtensionValidator(
|
validators.FileExtensionValidator(
|
||||||
['html'], _('TiddlyWiki files must be in HTML format'))
|
['html'],
|
||||||
], help_text=_(
|
_('TiddlyWiki files must be in HTML format'),
|
||||||
'Upload an existing TiddlyWiki file from this computer.'))
|
), _validate_not_index_file
|
||||||
|
],
|
||||||
|
help_text=_('Upload an existing TiddlyWiki file from this computer.'))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user