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

2006 trigger error on url in xform title #2007

Merged
merged 2 commits into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions onadata/apps/api/tests/viewsets/test_xform_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2710,15 +2710,42 @@ def test_update_xform_using_put_with_invalid_input(self):
'public_data': False,
'project': 'http://testserver/api/v1/projects/{0}'.format(
self.xform.project.pk),
'title': 'Transport Form',
'title': 'http://api.kfc.burger-king.nandos.io',
'version': unsanitized_html_str
}

with self.assertRaises(XLSFormError) as err:
request = self.factory.put('/', data=put_data, **self.extra)
response = view(request, pk=form_id)

self.assertEqual(
"Invalid title value; value shouldn't match a URL",
str(err.exception)
)

put_data['title'] = 'api.kfc.burger-king.nandos.io'

with self.assertRaises(XLSFormError) as err:
request = self.factory.put('/', data=put_data, **self.extra)
response = view(request, pk=form_id)

self.assertEqual(
"Invalid title value; value shouldn't match a URL",
str(err.exception)
)

put_data['title'] = 'Transport Form'

# trigger error is form version is invalid
with self.assertRaises(XLSFormError):
with self.assertRaises(XLSFormError) as err:
request = self.factory.put('/', data=put_data, **self.extra)
response = view(request, pk=form_id)

self.assertEqual(
"Version shouldn't have any invalid characters ('>' '&' '<')",
str(err.exception)
)

put_data['version'] = self.xform.version

request = self.factory.put('/', data=put_data, **self.extra)
Expand Down
4 changes: 4 additions & 0 deletions onadata/apps/logger/models/xform.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,10 @@ def _set_title(self):
_("Title shouldn't have any invalid xml "
"characters ('>' '&' '<')"))

if re.search(r"([://.]+)", self.title):
raise XLSFormError(
_("Invalid title value; value shouldn't match a URL"))

self.title = title_xml

def _set_hash(self):
Expand Down
Binary file not shown.