Skip to content

Commit

Permalink
Fix problem with urls with an @ present being invalid.
Browse files Browse the repository at this point in the history
Fix problem with urls with an @ present being invalid. Also bump the version to 1.1.4 and add some extra django, wagtail and python versions for testing.
  • Loading branch information
rubenhesselink committed Jul 25, 2024
1 parent 1c9980a commit 1faad40
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 42 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.11
python-version: 3.12

- name: Install dependencies
run: |
Expand All @@ -45,7 +45,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.11
python-version: 3.12

- name: Install dependencies
run: |
Expand Down Expand Up @@ -86,4 +86,4 @@ jobs:
body: |
Release for ${{ github.ref_name }}
draft: false
artifacts: dist/*
artifacts: dist/*
4 changes: 2 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.12

- name: Install dependencies
run: |
Expand All @@ -31,7 +31,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: ["3.8", "3.11"]
python-version: ["3.8", "3.11", "3.12"]
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion external_link/static/js/newtab.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function createAndHandleLinkForm(editorState, entityKey, onComplete) {
var urlPattern = new RegExp('^(https?:\\/\\/)?'+ // validate protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // validate domain name
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // validate OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // validate port and path
'(\\:\\d+)?(\\/[-a-z\\d%_.@~+]*)*'+ // validate port and path
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // validate query string
'(\\#[-a-z\\d_]*)?$','i'); // validate fragment locator
return !!urlPattern.test(urlString);
Expand Down
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exclude = ["sandbox*", "docs*", "tests*"]

[project]
name = "wagtail-external-link-richtext"
version = "1.1.3"
version = "1.1.4"
description = "A feature for the richtext fields in Wagtail"
readme = "README.md"
authors = [{name = "Ruben Hesselink", email = "[email protected]" }]
Expand All @@ -26,7 +26,8 @@ classifiers = [
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11"
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12"
]
keywords = ["richtext", "external", "link", "wagtail", "newtab", "django"]
dependencies = [
Expand All @@ -51,4 +52,4 @@ src_paths = ["test_project", "sandbox", "external_link"]

[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "test_project.settings.dev"
python_files = ["tests.py", "*_test.py", "testing/python/*.py"]
python_files = ["tests.py", "*_test.py", "testing/python/*.py"]
2 changes: 1 addition & 1 deletion sandbox/example_project/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@
# Add external link to richtext features
RICHTEXT_FEATURES = [
"new_tab_link",
]
]
5 changes: 2 additions & 3 deletions sandbox/example_project/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from django.conf import settings
from django.urls import include, path
from django.contrib import admin

from wagtail.admin import urls as wagtailadmin_urls
from django.urls import include, path
from wagtail import urls as wagtail_urls
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.documents import urls as wagtaildocs_urls

urlpatterns = [
Expand Down
10 changes: 5 additions & 5 deletions sandbox/home/migrations/0002_homepage_body.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Generated by Django 3.2.20 on 2023-07-05 10:55

from django.db import migrations
import wagtail.fields
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('home', '0001_initial'),
("home", "0001_initial"),
]

operations = [
migrations.AddField(
model_name='homepage',
name='body',
field=wagtail.fields.RichTextField(default='Test'),
model_name="homepage",
name="body",
field=wagtail.fields.RichTextField(default="Test"),
preserve_default=False,
),
]
9 changes: 3 additions & 6 deletions sandbox/home/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from django.db import models

from wagtail.models import Page
from wagtail.fields import RichTextField
from wagtail.admin.panels import FieldPanel
from wagtail.fields import RichTextField
from wagtail.models import Page


class HomePage(Page):
body = RichTextField()
content_panels = Page.content_panels + [
FieldPanel("body")
]
content_panels = Page.content_panels + [FieldPanel("body")]
2 changes: 1 addition & 1 deletion sandbox/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Django>=4.0,<4.1
wagtail>=3.0,<3.1
wagtail-external-link-richtext
wagtail-external-link-richtext
24 changes: 17 additions & 7 deletions test_project/test_app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
# Generated by Django 4.0.10 on 2023-07-06 07:05

from django.db import migrations, models
import django.db.models.deletion
import wagtail.fields
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
('wagtailcore', '0069_log_entry_jsonfield'),
("wagtailcore", "0069_log_entry_jsonfield"),
]

operations = [
migrations.CreateModel(
name='TestPage',
name="TestPage",
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')),
('body', wagtail.fields.RichTextField()),
(
"page_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="wagtailcore.page",
),
),
("body", wagtail.fields.RichTextField()),
],
options={
'abstract': False,
"abstract": False,
},
bases=('wagtailcore.page',),
bases=("wagtailcore.page",),
),
]
15 changes: 13 additions & 2 deletions test_project/test_app/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,22 @@ def test_to_database_format():
}
)
actual_database_html = converter.to_database_format(contentstate_json)
expected_database_html = (
expected_database_html_v1 = (
"<p "
'data-block-key="cfw9b">'
'<a href="http://www.fourdigits.nl" '
'rel="noopener noreferrer" '
'target="_blank">Four Digits</a></p>'
)
assert actual_database_html == expected_database_html
# From wagtail6.1 the order of the attributes is not guaranteed
expected_database_html_v2 = (
"<p "
'data-block-key="cfw9b">'
'<a href="http://www.fourdigits.nl" '
'target="_blank" '
'rel="noopener noreferrer">Four Digits</a></p>'
)
assert actual_database_html in {
expected_database_html_v1,
expected_database_html_v2,
}
6 changes: 2 additions & 4 deletions test_project/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from django.conf import settings
from django.urls import include, path
from django.contrib import admin

from wagtail.admin import urls as wagtailadmin_urls
from django.urls import include, path
from wagtail import urls as wagtail_urls
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.documents import urls as wagtaildocs_urls


urlpatterns = [
path("django-admin/", admin.site.urls),
path("admin/", include(wagtailadmin_urls)),
Expand Down
11 changes: 7 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[tox]
envlist =
py38-django32-wagtail{30,40}
py311-django{32,40,41}-wagtail{41,42,50}
py311-django{32,40,41}-wagtail{41,42,52}
py312-django{42,50}-wagtail{52,61}


[testenv]
Expand All @@ -12,13 +13,15 @@ ignore_errors = True
deps =
django32: django>=3.2,<3.3
django40: django>=4.0,<4.1
django41: django>=4.1,<4.2
django42: django>=4.2,<4.3
django50: django>=5.0,<5.1
djangomain: git+https://github.com/django/django.git@main#egg=Django
wagtail30: wagtail>=3.0,<3.1
wagtail40: wagtail>=4.0,<4.1
wagtail41: wagtail>=4.1,<4.2
wagtail42: wagtail>=4.2,<4.3
wagtail50: wagtail>=5.0,<5.1
wagtail52: wagtail>=5.2,<5.3
wagtail61: wagtail>=6.1,<6.2

commands =
pytest
pytest

0 comments on commit 1faad40

Please sign in to comment.