Skip to content

Commit

Permalink
https is always used to request the js files from the CDN (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
greendinosaur committed Sep 14, 2020
1 parent 5472239 commit a8f42fc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ This extension also supports the [Flask application factory pattern](http://flas

app = create_app(prod_config)

Note that jQuery is required. If you are already including it on your own then you can remove the `include_jquery()` line. Secure HTTP is used if the request under which these are executed is secure.
Note that jQuery is required. If you are already including it on your own then you can remove the `include_jquery()` line. Secure HTTP is always used to request the external js files..

The `include_jquery()` and `include_moment()` methods take some optional arguments. If you pass a `version` argument to any of these two calls, then the requested version will be loaded from the default CDN. If you pass `local_js`, then the given local path will be used to load the library. The `include_moment()` argument takes a third argument `no_js` that when set to `True` will assume that the Moment JavaScript library is already loaded and will only add the JavaScript code that supports this extension.

Expand Down
8 changes: 4 additions & 4 deletions flask_moment.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def include_moment(version=default_moment_version, local_js=None,
js_filename = 'moment.min.js'

if not sri:
js = ('<script src="//cdnjs.cloudflare.com/ajax/libs/'
js = ('<script src="https://cdnjs.cloudflare.com/ajax/libs/'
'moment.js/{}/{}"></script>\n').format(
version, js_filename)
else:
js = ('<script src="//cdnjs.cloudflare.com/ajax/libs/'
js = ('<script src="https://cdnjs.cloudflare.com/ajax/libs/'
'moment.js/{}/{}" integrity="{}" '
'crossorigin="anonymous"></script>\n').format(
version, js_filename, sri)
Expand Down Expand Up @@ -100,10 +100,10 @@ def include_jquery(version=default_jquery_version, local_js=None,

else:
if not sri:
js = ('<script src="//code.jquery.com/' +
js = ('<script src="https://code.jquery.com/' +
'jquery-{}.min.js"></script>').format(version)
else:
js = ('<script src="//code.jquery.com/jquery-{}.min.js" '
js = ('<script src="https://code.jquery.com/jquery-{}.min.js" '
'integrity="{}" crossorigin="anonymous">'
'</script>').format(version, sri)
return Markup(js)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_flask_moment.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def test_jquery_from_cdn_without_custom_sri_hash(self):
include_jquery = _moment.include_jquery(version='2.1.1',
sri='sha384-12345678')

assert ('<script src=\"//code.jquery.com/jquery-2.1.1.min.js\"'
assert ('<script src=\"https://code.jquery.com/jquery-2.1.1.min.js\"'
' integrity=\"sha384-12345678\" crossorigin=\"anonymous\">'
'</script>') == include_jquery

Expand Down Expand Up @@ -361,7 +361,7 @@ def test_moment_with_default_version(self):
include_moment = _moment.include_moment()

assert include_moment.startswith(
'<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/{}'
'<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/{}'
'/moment-with-locales.min.js" integrity="{}" '
'crossorigin="anonymous"></script>'.format(
default_moment_version, default_moment_sri))
Expand All @@ -370,15 +370,15 @@ def test_moment_from_cdn_with_custom_sri_hash(self):
include_moment = _moment.include_moment(sri='sha384-12345678')

assert include_moment.startswith(
'<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/{}'
'<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/{}'
'/moment-with-locales.min.js" integrity="sha384-12345678" '
'crossorigin="anonymous"></script>'.format(default_moment_version))

include_moment = _moment.include_moment(version='2.0.0',
sri='sha384-12345678')

assert include_moment.startswith(
'<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.0.0'
'<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.0.0'
'/moment-with-langs.min.js" integrity="sha384-12345678" '
'crossorigin="anonymous"></script>')

Expand Down

0 comments on commit a8f42fc

Please sign in to comment.