Skip to content

Commit

Permalink
Enforce https:// for CDN URLs (fixes applegrew#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
hartwork committed May 23, 2020
1 parent 2d8a536 commit fe801e0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions django_select2/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Select2Conf(AppConf):
It has set `select2_` as a default value, which you can change if needed.
"""

JS = '//cdnjs.cloudflare.com/ajax/libs/select2/{version}/js/select2.min.js'.format(version=LIB_VERSION)
JS = 'https://cdnjs.cloudflare.com/ajax/libs/select2/{version}/js/select2.min.js'.format(version=LIB_VERSION)
"""
The URI for the Select2 JS file. By default this points to the Cloudflare CDN.
Expand All @@ -74,7 +74,7 @@ class Select2Conf(AppConf):
develop without an Internet connection.
"""

CSS = '//cdnjs.cloudflare.com/ajax/libs/select2/{version}/css/select2.min.css'.format(version=LIB_VERSION)
CSS = 'https://cdnjs.cloudflare.com/ajax/libs/select2/{version}/css/select2.min.css'.format(version=LIB_VERSION)
"""
The URI for the Select2 CSS file. By default this points to the Cloudflare CDN.
Expand All @@ -92,7 +92,7 @@ class Select2Conf(AppConf):
develop without an Internet connection.
"""

I18N_PATH = '//cdnjs.cloudflare.com/ajax/libs/select2/{version}/js/i18n'.format(version=LIB_VERSION)
I18N_PATH = 'https://cdnjs.cloudflare.com/ajax/libs/select2/{version}/js/i18n'.format(version=LIB_VERSION)
"""
The base URI for the Select2 i18n files. By default this points to the Cloudflare CDN.
Expand Down
26 changes: 13 additions & 13 deletions tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,44 +102,44 @@ def test_empty_option(self, db):
def test_i18n(self):
translation.activate('de')
assert tuple(Select2Widget().media._js) == (
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/de.js',
f'https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
f'https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/de.js',
'django_select2/django_select2.js'
)

translation.activate('en')
assert tuple(Select2Widget().media._js) == (
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/en.js',
f'https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
f'https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/en.js',
'django_select2/django_select2.js'
)

translation.activate('00')
assert tuple(Select2Widget().media._js) == (
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
f'https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
'django_select2/django_select2.js'
)

translation.activate('sr-cyrl')
assert tuple(Select2Widget().media._js) == (
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/sr-Cyrl.js',
f'https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
f'https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/sr-Cyrl.js',
'django_select2/django_select2.js'
)

pytest.importorskip("django", minversion="2.0.4")

translation.activate('zh-hans')
assert tuple(Select2Widget().media._js) == (
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/zh-CN.js',
f'https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
f'https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/zh-CN.js',
'django_select2/django_select2.js'
)

translation.activate('zh-hant')
assert tuple(Select2Widget().media._js) == (
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/zh-TW.js',
f'https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
f'https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/zh-TW.js',
'django_select2/django_select2.js'
)

Expand All @@ -148,8 +148,8 @@ class TestSelect2MixinSettings:
def test_default_media(self):
sut = Select2Widget()
result = sut.media.render()
assert f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js' in result
assert f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/css/select2.min.css' in result
assert f'https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js' in result
assert f'https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/css/select2.min.css' in result
assert 'django_select2/django_select2.js' in result

def test_js_setting(self, settings):
Expand Down
2 changes: 1 addition & 1 deletion tests/testapp/templates/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{{ form }}
<input type="submit" value="Submit Form"/>
</form>
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript">
window.onerror = function (msg) {
$("body").attr("JSError", msg);
Expand Down

0 comments on commit fe801e0

Please sign in to comment.