Skip to content

Commit 16111d0

Browse files
committed
Escape values for environment variables before saving them
1 parent 0897532 commit 16111d0

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

readthedocs/projects/models.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import logging
99
import os
1010
from builtins import object # pylint: disable=redefined-builtin
11+
from six.moves import shlex_quote
1112

1213
from django.conf import settings
1314
from django.contrib.auth.models import User
@@ -1132,6 +1133,7 @@ def get_feature_display(self):
11321133
return dict(self.FEATURES).get(self.feature_id, self.feature_id)
11331134

11341135

1136+
@python_2_unicode_compatible
11351137
class EnvironmentVariable(TimeStampedModel, models.Model):
11361138
name = models.CharField(
11371139
max_length=128,
@@ -1146,3 +1148,10 @@ class EnvironmentVariable(TimeStampedModel, models.Model):
11461148
on_delete=models.CASCADE,
11471149
help_text=_('Project where this variable will be used'),
11481150
)
1151+
1152+
def __str__(self):
1153+
return self.name
1154+
1155+
def save(self, *args, **kwargs): # pylint: disable=arguments-differ
1156+
self.value = shlex_quote(self.value)
1157+
return super(EnvironmentVariable, self).save(*args, **kwargs)

readthedocs/templates/projects/environmentvariable_form.html

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@
1212
{% block project_edit_content_header %}{% trans "Environment Variables" %}{% endblock %}
1313

1414
{% block project_edit_content %}
15-
<p>
16-
{% blocktrans trimmed %}
17-
Notice that the values are not escaped when your builds are executed.
18-
Special characters (for bash) should be escaped accordingly.
19-
{% endblocktrans %}
20-
</p>
2115
<form
2216
method="post"
2317
action="{% url 'projects_environmentvariables_create' project_slug=project.slug %}">

0 commit comments

Comments
 (0)