Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pages break entire site when containing an <img> tag without src attribute #131

Open
ComaVN opened this issue Apr 2, 2024 · 1 comment

Comments

@ComaVN
Copy link

ComaVN commented Apr 2, 2024

If I just put this in a page:

foo <img> bar

the entire site fails (not just that page) with an nginx 404 and the following is in the log:

ckan              | 2024-04-02 09:31:58,907 ERROR [ckan.config.middleware.flask_app] 'src'
ckan              | Traceback (most recent call last):
ckan              |   File "/usr/lib/python3.10/site-packages/flask/app.py", line 1516, in full_dispatch_request
ckan              |     rv = self.dispatch_request()
ckan              |   File "/usr/lib/python3.10/site-packages/flask/app.py", line 1502, in dispatch_request
ckan              |     return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
ckan              |   File "/srv/app/src/ckanext-pages/ckanext/pages/blueprint.py", line 13, in show
ckan              |     return utils.pages_show(page, page_type='page')
ckan              |   File "/srv/app/src/ckanext-pages/ckanext/pages/utils.py", line 187, in pages_show
ckan              |     return tk.render('ckanext_pages/%s.html' % page_type)
ckan              |   File "/srv/app/src/ckan/ckan/lib/base.py", line 107, in render
ckan              |     return flask_render_template(template_name, **extra_vars)
ckan              |   File "/usr/lib/python3.10/site-packages/flask/templating.py", line 147, in render_template
ckan              |     return _render(
ckan              |   File "/usr/lib/python3.10/site-packages/flask/templating.py", line 128, in _render
ckan              |     rv = template.render(context)
ckan              |   File "/usr/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render
ckan              |     self.environment.handle_exception()
ckan              |   File "/usr/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception
ckan              |     raise rewrite_traceback_stack(source=source)
ckan              |   File "/srv/app/src/ckanext-pages/ckanext/pages/theme/templates_main/ckanext_pages/page.html", line 1, in top-level template code
ckan              |     {% extends 'page.html' %}
ckan              |   File "/srv/app/src/ckan/ckan/templates/page.html", line 1, in top-level template code
ckan              |     {% extends "base.html" %}
ckan              |   File "/srv/app/src/ckanext-harvest/ckanext/harvest/templates/base.html", line 1, in top-level template code
ckan              |     {% ckan_extends %}
ckan              |   File "/srv/app/src/ckanext-fds-theme/ckanext/fds_theme/templates/base.html", line 1, in top-level template code
ckan              |     {% ckan_extends %}
ckan              |   File "/srv/app/src/ckan/ckan/templates/base.html", line 108, in top-level template code
ckan              |     {%- block page %}{% endblock -%}
ckan              |   File "/srv/app/src/ckan/ckan/templates/page.html", line 14, in block 'page'
ckan              |     {%- block header %}
ckan              |   File "/srv/app/src/ckan/ckan/templates/page.html", line 15, in block 'header'
ckan              |     {% include "header.html" %}
ckan              |   File "/srv/app/src/ckanext-pages/ckanext/pages/theme/templates_main/header.html", line 1, in top-level template code
ckan              |     {% ckan_extends %}
ckan              |   File "/srv/app/src/ckan/ckan/templates/header.html", line 3, in top-level template code
ckan              |     {% block header_wrapper %} {% block header_account %}
ckan              |   File "/srv/app/src/ckan/ckan/templates/header.html", line 96, in block 'header_wrapper'
ckan              |     {% block header_site_navigation %}
ckan              |   File "/srv/app/src/ckan/ckan/templates/header.html", line 97, in block 'header_site_navigation'
ckan              |     {% block header_site_navigation_tabs %}
ckan              |   File "/srv/app/src/ckan/ckan/templates/header.html", line 101, in block 'header_site_navigation_tabs'
ckan              |     {{ h.build_nav_main(
ckan              |   File "/srv/app/src/ckanext-pages/ckanext/pages/plugin.py", line 42, in build_pages_nav_main
ckan              |     pages_list = tk.get_action('ckanext_pages_list')(None, {'order': True, 'private': False})
ckan              |   File "/srv/app/src/ckan/ckan/logic/__init__.py", line 580, in wrapped
ckan              |     result = _action(context, data_dict, **kw)
ckan              |   File "/srv/app/src/ckanext-pages/ckanext/pages/actions.py", line 211, in pages_list
ckan              |     return _pages_list(context, data_dict)
ckan              |   File "/srv/app/src/ckanext-pages/ckanext/pages/actions.py", line 71, in _pages_list
ckan              |     parser.feed(pg.content)
ckan              |   File "/usr/lib/python3.10/html/parser.py", line 110, in feed
ckan              |     self.goahead(0)
ckan              |   File "/usr/lib/python3.10/html/parser.py", line 170, in goahead
ckan              |     k = self.parse_starttag(i)
ckan              |   File "/usr/lib/python3.10/html/parser.py", line 344, in parse_starttag
ckan              |     self.handle_starttag(tag, attrs)
ckan              |   File "/srv/app/src/ckanext-pages/ckanext/pages/actions.py", line 26, in handle_starttag
ckan              |     self.first_image = dict(attrs)['src']
ckan              | KeyError: 'src'
ckan              | 2024-04-02 09:31:58,918 ERROR [ckan.config.middleware.flask_app] Exception on /pages/begrippen [GET]

versions:

# pip list
Package               Version     Editable project location
--------------------- ----------- ------------------------------
alembic               1.8.1
Babel                 2.10.3
Beaker                1.11.0
bleach                5.0.1
blinker               1.5
certifi               2021.10.8
cffi                  1.15.1
charset-normalizer    2.0.12
ckan                  2.10.4      /srv/app/src/ckan
ckanext-dcat          1.5.1       /srv/app/src/ckanext-dcat
ckanext-envvars       0.0.4       /srv/app/src/ckanext-envvars
ckanext-fds-theme     0.0.2       /srv/app/src/ckanext-fds-theme
ckanext-harvest       1.5.6       /srv/app/src/ckanext-harvest
ckanext-pages         0.5.2       /srv/app/src/ckanext-pages
ckantoolkit           0.0.7
click                 8.1.3
Deprecated            1.2.13
dominate              2.7.0
feedgen               0.9.0
Flask                 2.0.3
Flask-Babel           1.0.0
Flask-Login           0.6.1
flask-multistatic     1.0
Flask-WTF             1.0.1
future                1.0.0
geomet                1.1.0
gevent                22.10.2
greenlet              2.0.2
idna                  3.3
importlib-metadata    4.11.3
isodate               0.6.1
itsdangerous          2.1.1
Jinja2                3.1.2
lxml                  4.9.1
Mako                  1.2.2
Markdown              3.4.1
MarkupSafe            2.1.1
mypy                  0.971
mypy-extensions       0.4.3
nose                  1.3.7
packaging             21.3
passlib               1.7.4
pika                  1.2.1
pip                   24.0
polib                 1.1.1
psycopg2              2.9.3
pycparser             2.21
PyJWT                 2.4.0
pyparsing             3.0.7
pysolr                3.9.0
python-dateutil       2.8.2
python-magic          0.4.27
pytz                  2021.3
pytz-deprecation-shim 0.1.0.post0
PyUtilib              6.0.0
PyYAML                6.0.1
rdflib                6.1.1
redis                 4.1.4
requests              2.28.1
rq                    1.11.0
setuptools            65.6.0
simplejson            3.17.6
six                   1.16.0
SQLAlchemy            1.4.41
sqlalchemy2-stubs     0.0.2a27
sqlparse              0.4.2
supervisor            4.2.5
tomli                 2.0.1
typing_extensions     4.3.0
tzdata                2022.1
tzlocal               4.2
urllib3               1.26.9
watchdog              2.1.6
webassets             2.0
webencodings          0.5.1
Werkzeug              2.0.3
wheel                 0.43.0
wrapt                 1.14.0
WTForms               3.0.1
zipp                  3.7.0
zope.event            4.5.0
zope.interface        5.4.0

(running using docker compose from a slightly adapted fork of ckan-docker)

If I remove the page content directly in the database it works again.

@ComaVN ComaVN changed the title pages break when containing an <img> tag with src attribute pages break entire site when containing an <img> tag with src attribute Apr 2, 2024
@ComaVN ComaVN changed the title pages break entire site when containing an <img> tag with src attribute pages break entire site when containing an <img> tag without src attribute Apr 2, 2024
RickMoynihan added a commit to RickMoynihan/ckanext-pages that referenced this issue Oct 4, 2024
RickMoynihan added a commit to RickMoynihan/ckanext-pages that referenced this issue Oct 4, 2024
@RickMoynihan
Copy link

Just a note to say I have seen this issue too; and there is a candidate fix for it in this PR #138

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants