Repository: mrf345/flask_minify

Issue:
Some whitespace in template literals is wrongly removed
```python
#!/usr/bin/env python3

from flask import Flask
from flask_minify import minify

app = Flask(__name__)
minify(app=app, js=True)

@app.route('/')
def index():
  return '<script>const x = 42; document.write(`foo ${x} bar`)</script>'
```
This produces the following response on `GET /`:
```js
<script>const x=42;document.write(`foo ${x}bar`)</script>
```
The output is missing a space character after `${x}`. The error occurs only if `x` is enclosed by curly brackets.

Discussion:

Patch:
diff --git a/.flake8 b/.flake8
new file mode 100644
index 0000000..03782a5
--- /dev/null
+++ b/.flake8
@@ -0,0 +1,3 @@
+[flake8]
+exclude = .eggs,.nox,.venv,__pycache__,*.pyc
+max-complexity = 20
diff --git a/.travis.yml b/.travis.yml
index 0a12d98..b49b9f4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,14 +1,14 @@
 language: python
 python:
-  - "2.7"
-  - "3.5"
-  - "3.6"
-  - "3.7"
-  - "3.8"
+  - "2.7.18"
+  - "3.5.9"
+  - "3.6.10"
+  - "3.7.7"
+  - "3.8.3"
 # command to install dependencies
 install:
   - pip install -r requirements/test.txt
 # command to run tests
-script: python setup.py lint test 
+script: flake8 && pytest
 after_success:
   - coveralls
diff --git a/README.md b/README.md
index 02aff0d..865e919 100644
--- a/README.md
+++ b/README.md
@@ -103,5 +103,5 @@ def __init__(
 ```
 
 ## Development:
-- **Run Tests:** `python setup.py test`
-- **Run style checks:** `python setup.py lint`
+- **Run Tests:** `flake8`
+- **Run style checks:** `pytest`
diff --git a/flask_minify/about.py b/flask_minify/about.py
index 1d98b14..5ef8be6 100644
--- a/flask_minify/about.py
+++ b/flask_minify/about.py
@@ -1,4 +1,4 @@
-__version__ = '0.20'
+__version__ = '0.21'
 __doc__ = 'Flask extension to minify html, css, js and less.'
 __license__ = 'MIT'
 __author__ = 'Mohamed Feddad'
diff --git a/flask_minify/main.py b/flask_minify/main.py
index c06a2de..f3df0f3 100644
--- a/flask_minify/main.py
+++ b/flask_minify/main.py
@@ -150,7 +150,9 @@ class minify(object):
                                     minify=True,
                                     xminify=True)
             elif tag == 'script':
-                return jsmin(content).replace('\n', ';')
+                return jsmin(content,
+                             quote_chars="'\"`"
+                             ).replace('\n', ';')
             else:
                 return minify_html(content)
 
diff --git a/noxfile.py b/noxfile.py
index 09b5ddd..16dd667 100644
--- a/noxfile.py
+++ b/noxfile.py
@@ -6,13 +6,10 @@ SUPPORTED_VERSIONS = ['2.7', '3.5', '3.6', '3.7', '3.8']
 @nox.session(python=SUPPORTED_VERSIONS)
 def lint(s):
     s.install('flake8')
-    s.run('flake8', 'flask_minify')
+    s.run('flake8')
 
 
 @nox.session(python=SUPPORTED_VERSIONS)
 def test(s):
     s.install('-r', './requirements/test.txt')
-    s.run('py.test',
-          '--cov=./flask_minify',
-          './tests/integration.py',
-          './tests/units.py')
+    s.run('pytest')
diff --git a/setup.cfg b/setup.cfg
index 79ea43b..3380a41 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,15 +1,6 @@
 [metadata]
 description-file = README.md
 
-[aliases]
-test='pytest'
-lint='flake8'
-
 [tool:pytest]
 addopts = --verbose --cov='./flask_minify'
 python_files = tests/integration.py tests/units.py
-
-[flake8]
-ignore = 
-exclude = .git,__pycache__,build,dist,setup.py
-max-complexity = 20
diff --git a/setup.py b/setup.py
index 1b14a15..e79db5f 100644
--- a/setup.py
+++ b/setup.py
@@ -6,6 +6,7 @@ basedir = path.abspath(path.dirname(__file__))
 long_description = ''
 requirements = []
 test_requirements = []
+requirements_path = path.join(basedir, 'requirements')
 
 
 with open(path.join(basedir, path.join('flask_minify', 'about.py'))) as f:
@@ -14,24 +15,26 @@ with open(path.join(basedir, path.join('flask_minify', 'about.py'))) as f:
 with open(path.join(basedir, 'README.md')) as f:
     long_description += f.read()
 
-with open(path.join(basedir, 'requirements/main.txt')) as f:
-    requirements += [l for l in f.read().split('\n') if l]
+with open(path.join(requirements_path, 'main.txt')) as f:
+    requirements += [line for line in f.read().split('\n') if line]
     test_requirements += requirements
 
-with open(path.join(basedir, 'requirements/test.txt')) as f:
-    test_requirements += [l for l in f.read().split('\n') if l and not l.startswith('-r')]
+with open(path.join(requirements_path, 'test.txt')) as f:
+    test_requirements += [
+        line for line in f.read().split('\n')
+        if line and not line.startswith('-r')]
 
 
 setup(
     name='Flask-Minify',
-    version=__version__,
+    version=__version__,  # noqa
     url='https://github.com/mrf345/flask_minify/',
     download_url='https://github.com/mrf345/flask_minify/archive/%s.tar.gz'
-    % __version__,
-    license=__license__,
-    author=__author__,
-    author_email=__email__,
-    description=__doc__,
+    % __version__,  # noqa
+    license=__license__,  # noqa
+    author=__author__,  # noqa
+    author_email=__email__,  # noqa
+    description=__doc__,  # noqa
     long_description=long_description,
     long_description_content_type='text/markdown',
     packages=['flask_minify'],


Test patch:
diff --git a/tests/constants.py b/tests/constants.py
index 40f92e5..3a0916a 100644
--- a/tests/constants.py
+++ b/tests/constants.py
@@ -42,6 +42,11 @@ body    {
 }
 '''
 
+JS_TEMPLATE_LITERALS = '''
+const a = 'something'
+const b = ` more  than    ${a}  `
+'''
+
 MINIFED_HTML = b'<html> <body> <h1> HTML </h1> </body> </html>'
 
 MINIFIED_JS = b'<script>["J","S"].reduce(function(a,r){return a+r})</script>'
@@ -52,6 +57,9 @@ MINIFIED_JS_RAW = b"console.warn(['testing',' suite']);"
 
 MINIFIED_LESS_RAW = b'body{color:red;}'
 
+MINIFIED_JS_TEMPLATE_LITERALS =\
+    "const a='something';const b=` more  than    ${a}  `"
+
 
 def MINIFED_STRIPED(value):
     constant = globals().get(value, '')
diff --git a/tests/units.py b/tests/units.py
index 6725273..2001ea6 100644
--- a/tests/units.py
+++ b/tests/units.py
@@ -3,6 +3,7 @@ from os import path
 from importlib import import_module
 
 from flask_minify.utils import (is_empty, is_html, is_cssless, is_js)
+from .constants import (JS_TEMPLATE_LITERALS, MINIFIED_JS_TEMPLATE_LITERALS)
 
 
 sys_path.append(path.dirname(path.dirname(__file__)))
@@ -36,6 +37,12 @@ class TestUtils:
         assert is_cssless(mock.Mock(content_type='text/css')) is True
         assert is_cssless(mock.Mock(content_type='text/less')) is True
 
+    def test_jsmin_template_literals(self):
+        ''' Test `jsmin` template literals white spaces sanity '''
+
+        assert minify.get_minified(JS_TEMPLATE_LITERALS, 'script')\
+            == MINIFIED_JS_TEMPLATE_LITERALS
+
 
 class TestMinifyRequest:
     def setup(self):