Skip to content

Commit

Permalink
Merge pull request #12 from bernhard-hagmann/SIANXKE-404
Browse files Browse the repository at this point in the history
SIANXKE-404: Update Python, Django, and package versions
  • Loading branch information
nezhar authored Nov 8, 2024
2 parents 358ccfb + ac3b3c8 commit 9c1add1
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 65 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.13'
architecture: 'x64'

- name: Install dependencies
Expand Down
25 changes: 13 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,26 @@ jobs:
fail-fast: false
matrix:
python-version:
- '3.7'
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- '3.12'
- '3.13'
django-version:
- '3.2'
- '4.0'
- '4.1'
- '4.2'
- '5.0'
- '5.1'
exclude:
- python-version: '3.7'
django-version: '4.0'
- python-version: '3.7'
django-version: '4.1'
- python-version: '3.9'
django-version: '5.0'
- python-version: '3.9'
django-version: '5.1'

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -58,4 +59,4 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.4.0]
### Removed
- Dropped support for Django 3.2, 4.0, 4.1
- Dropped support for Python 3.7 and 3.8
### Added
- Added support for Django 4.2, 5.0, and 5.1
- Added support for Python 3.11, 3.12, and 3.13

## [1.3.0]
### Removed
- Dropped support for Django 2.2
Expand Down Expand Up @@ -37,7 +45,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Initial Release

[Unreleased]: https://github.com/anexia/django-cleanhtmlfield/compare/v1.3.0...HEAD
[Unreleased]: https://github.com/anexia/django-cleanhtmlfield/compare/v1.4.0...HEAD
[1.4.0]: https://pypi.org/project/django-cleanhtmlfield/1.4.0/
[1.3.0]: https://pypi.org/project/django-cleanhtmlfield/1.3.0/
[1.2.0]: https://pypi.org/project/django-cleanhtmlfield/1.2.0/
[1.1.0]: https://pypi.org/project/django-cleanhtmlfield/1.1.0/
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,12 @@ ModelSerializer.serializer_field_mapping[HTMLField] = RestHtmlField
This library should be compatible with the latest Django. For reference, here is a matrix showing
the guaranteed and tested compatibility.

django-cleanhtmlfield Version | Django Versions | Python
----------------------------- | --------------- | ------
1.1 | 2.2, 3.0, 3.1 | 3.5 - 3.8
1.2 | 2.2, 3.1, 3.2 | 3.7 - 3.10
1.3 | 3.2, 4.0, 4.1 | 3.7 - 3.10
| django-cleanhtmlfield Version | Django Versions | Python |
|-------------------------------|-----------------|------------|
| 1.1 | 2.2, 3.0, 3.1 | 3.5 - 3.8 |
| 1.2 | 2.2, 3.1, 3.2 | 3.7 - 3.10 |
| 1.3 | 3.2, 4.0, 4.1 | 3.7 - 3.10 |
| 1.4 | 4.2, 5.0, 5.1 | 3.9 - 3.13 |

# License

Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

# Development dependencies
codecov>=2.1
setuptools>=42
wheel>=0.37
twine>=3.4
setuptools>=75
wheel>=0.44
twine>=5.1
13 changes: 7 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,25 @@
author_email='[email protected]',
install_requires=[
'django',
'beautifulsoup4>=4.6,<5',
'beautifulsoup4>=4.12,<4.13',
],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Framework :: Django',
'Framework :: Django :: 2.2',
'Framework :: Django :: 3.1',
'Framework :: Django :: 3.2',
'Framework :: Django :: 4.2',
'Framework :: Django :: 5.0',
'Framework :: Django :: 5.1',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
Expand Down
11 changes: 6 additions & 5 deletions tests/cleanhtmlfield_testapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
Generated by 'django-admin startproject' using Django 1.8.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
https://docs.djangoproject.com/en/stable/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
https://docs.djangoproject.com/en/stable/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
Expand All @@ -19,7 +19,7 @@


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# See https://docs.djangoproject.com/en/stable/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "!u-4q!$+GO2_=!$p&0cr*57z1oN72sady26&8"
Expand Down Expand Up @@ -86,9 +86,10 @@
}
}

DEFAULT_AUTO_FIELD = "django.db.models.AutoField"

# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
# https://docs.djangoproject.com/en/stable/topics/i18n/

LANGUAGE_CODE = "en-us"

Expand All @@ -102,7 +103,7 @@


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
# https://docs.djangoproject.com/en/stable/howto/static-files/

STATIC_URL = "/static/"

Expand Down
6 changes: 3 additions & 3 deletions tests/cleanhtmlfield_testapp/test_clean_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ def test_clean_script_tags(self):
Tests that javascript "script" tags are removed
:return:
"""
self.assertEquals(
self.assertEqual(
"<p>test</p>",
clean_html(
"<p>test</p><script>alert('hello');</script>", strip_unsafe=True
),
"<p>test</p>",
)

def test_clean_html_keep_it(self):
Expand All @@ -28,4 +28,4 @@ def test_clean_html_keep_it(self):
<h3>Some title</h3>
<p>I am Groot. <i>I am Groot</i>. I am Groot. We are Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. We are Groot. We are Groot. We are Groot. We are Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. We are Groot.
</p>"""
self.assertEquals(clean_html(some_html_str), some_html_str)
self.assertEqual(some_html_str, clean_html(some_html_str))
36 changes: 18 additions & 18 deletions tests/cleanhtmlfield_testapp/tests_clean_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,50 @@ def test_clean_styles_multiple_double_dots(self):
Tests that cleaning css styles leaves styles with multiple dots in place
:return:
"""
self.assertEquals(clean_styles("color:red:foo();"), "color:red:foo();")
self.assertEqual("color:red:foo();", clean_styles("color:red:foo();"))

def test_clean_styles_adds_semicolon(self):
"""
Tests whether clean styles add a semicolon
:return:
"""
self.assertEquals(clean_styles("color:red"), "color:red;")
self.assertEqual("color:red;", clean_styles("color:red"))

self.assertEquals(
clean_styles("color:red; font-size:10pt"), "color:red;font-size:10pt;"
self.assertEqual(
"color:red;font-size:10pt;", clean_styles("color:red; font-size:10pt")
)

def test_clean_styles_single(self):
"""
Tests that cleaning styles removes extra spaces
:return:
"""
self.assertEquals(clean_styles("padding: 9px; "), "padding:9px;")
self.assertEqual("padding:9px;", clean_styles("padding: 9px; "))

self.assertEquals(clean_styles("margin: 9px; "), "margin:9px;")
self.assertEqual("margin:9px;", clean_styles("margin: 9px; "))

self.assertEquals(clean_styles("padding-top: 9px; "), "padding-top:9px;")
self.assertEqual("padding-top:9px;", clean_styles("padding-top: 9px; "))

def test_clean_styles_multiple(self):
"""
Tests that cleaning styles works with multiple styles
:return:
"""
self.assertEquals(
clean_styles("padding: 9px; margin-top: 10px; margin-bottom: 10px;"),
self.assertEqual(
"padding:9px;margin-top:10px;margin-bottom:10px;",
clean_styles("padding: 9px; margin-top: 10px; margin-bottom: 10px;"),
)

def test_clean_styles_invalid_element(self):
"""
Tests that cleaning styles removes invalid elements
:return:
"""
self.assertEquals(
self.assertEqual(
"padding:9px;margin-bottom:10px;",
clean_styles(
"padding: 9px; some-invalid-attribute: 10px; margin-bottom: 10px;"
),
"padding:9px;margin-bottom:10px;",
)

def test_clean_styles_preserve_styles_whitespace(self):
Expand All @@ -61,18 +61,18 @@ def test_clean_styles_preserve_styles_whitespace(self):
:return:
"""
with self.settings(PRESERVE_STYLES_WHITESPACE=True):
self.assertEquals(clean_styles("padding: 9px; "), "padding: 9px;")
self.assertEqual("padding: 9px;", clean_styles("padding: 9px; "))

self.assertEquals(clean_styles("padding : 9px; "), "padding : 9px;")
self.assertEqual("padding : 9px;", clean_styles("padding : 9px; "))

self.assertEquals(clean_styles("padding: 9px; "), "padding: 9px;")
self.assertEqual("padding: 9px;", clean_styles("padding: 9px; "))

self.assertEquals(
clean_styles("padding: 9px; margin-top: 10px; margin-bottom: 10px;"),
self.assertEqual(
"padding: 9px; margin-top: 10px; margin-bottom: 10px;",
clean_styles("padding: 9px; margin-top: 10px; margin-bottom: 10px;"),
)

self.assertEquals(
clean_styles("padding: 9px;margin-top: 10px;margin-bottom: 10px;"),
self.assertEqual(
"padding: 9px;margin-top: 10px;margin-bottom: 10px;",
clean_styles("padding: 9px;margin-top: 10px;margin-bottom: 10px;"),
)
18 changes: 9 additions & 9 deletions tests/myapp/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def test_try_save_with_invalid_content(self):
:return:
"""
malicious_html_string = """<h1>Groot Ipsum</h1>
<script type="text/javascript">
alert('Do something evil in Javascript');
</script>
<p>I am Groot. I am Groot. I am Groot. We are Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. We are Groot. We are Groot. We are Groot. We are Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. We are Groot. </p>
<p>I am Groot. I am Groot. <span style="color:red">I am Groot</span>. We are Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. We are Groot. We are Groot. We are Groot. We are Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. We are Groot.
</p>
<h3>Some title</h3>
<p>I am Groot. <i>I am Groot</i>. I am Groot. We are Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. We are Groot. We are Groot. We are Groot. We are Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. We are Groot.
</p>"""
<script type="text/javascript">
alert('Do something evil in Javascript');
</script>
<p>I am Groot. I am Groot. I am Groot. We are Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. We are Groot. We are Groot. We are Groot. We are Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. We are Groot. </p>
<p>I am Groot. I am Groot. <span style="color:red">I am Groot</span>. We are Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. We are Groot. We are Groot. We are Groot. We are Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. We are Groot.
</p>
<h3>Some title</h3>
<p>I am Groot. <i>I am Groot</i>. I am Groot. We are Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. We are Groot. We are Groot. We are Groot. We are Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. We are Groot.
</p>"""
obj = MyModel()
obj.some_html_field = malicious_html_string
obj.save()
Expand Down
2 changes: 2 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
django>=4.2,<=5.2
beautifulsoup4>=4.12,<4.13

0 comments on commit 9c1add1

Please sign in to comment.