Files
@ 7aff9a999536
Branch filter:
Location: kallithea/docs/index.rst - annotation
7aff9a999536
1.3 KiB
text/prs.fallenstein.rst
templates, controllers: replace webhelpers.html.literal() with webhelpers.html.HTML() where possible
Usage of webhelpers.literal (h.literal) can be a problem when variables are
not correctly escaped. Luckily, this function can be avoided in several
cases.
Several users of the construct:
h.literal(_('..A..') % (..B..))
can be simplified if (..B..) just contains a call to h.link_to. In this
case, there is actually no need to use h.literal, because the object
returned by link_to is already a literal. It is sufficient to use
webhelpers.html.HTML() like so:
h.HTML(_('..A..')) % (..B..)
which is better because it will escape the '..A..' part instead of passing
it literally.
The need to wrap the '..A..' part in HTML() is to make sure the (escaped)
end result is not a plain string but a 'literal' to avoid double escaping
later.
See also the documentation:
https://docs.pylonsproject.org/projects/webhelpers/en/latest/modules/html/builder.html
"
When literal is used in a mixed expression containing both literals and
ordinary strings, it tries hard to escape the strings and return a
literal. However, this depends on which value has “control” of the
expression. literal seems to be able to take control with all
combinations of the + operator, but with % and join it must be on the
left side of the expression. So these all work:
"A" + literal("B")
literal(", ").join(["A", literal("B")])
literal("%s %s") % (16, literal("kg"))
But these return an ordinary string which is prone to double-escaping later:
"\n".join([literal('<span class="foo">Foo!</span>'), literal('Bar!')])
"%s %s" % (literal("16"), literal("<em>kg</em>"))
"
This same escaping with 'HTML()' was already done by default in mako
templates for constructs like ${_("something")} that do not contain format
specifiers. When the translated string _does_ contain format specifiers, we
want to use the same escaping, but we have to do it explicit and earlier so
the escaping happens already when strings are inserted into the template
string.
Usage of webhelpers.literal (h.literal) can be a problem when variables are
not correctly escaped. Luckily, this function can be avoided in several
cases.
Several users of the construct:
h.literal(_('..A..') % (..B..))
can be simplified if (..B..) just contains a call to h.link_to. In this
case, there is actually no need to use h.literal, because the object
returned by link_to is already a literal. It is sufficient to use
webhelpers.html.HTML() like so:
h.HTML(_('..A..')) % (..B..)
which is better because it will escape the '..A..' part instead of passing
it literally.
The need to wrap the '..A..' part in HTML() is to make sure the (escaped)
end result is not a plain string but a 'literal' to avoid double escaping
later.
See also the documentation:
https://docs.pylonsproject.org/projects/webhelpers/en/latest/modules/html/builder.html
"
When literal is used in a mixed expression containing both literals and
ordinary strings, it tries hard to escape the strings and return a
literal. However, this depends on which value has “control” of the
expression. literal seems to be able to take control with all
combinations of the + operator, but with % and join it must be on the
left side of the expression. So these all work:
"A" + literal("B")
literal(", ").join(["A", literal("B")])
literal("%s %s") % (16, literal("kg"))
But these return an ordinary string which is prone to double-escaping later:
"\n".join([literal('<span class="foo">Foo!</span>'), literal('Bar!')])
"%s %s" % (literal("16"), literal("<em>kg</em>"))
"
This same escaping with 'HTML()' was already done by default in mako
templates for constructs like ${_("something")} that do not contain format
specifiers. When the translated string _does_ contain format specifiers, we
want to use the same escaping, but we have to do it explicit and earlier so
the escaping happens already when strings are inserted into the template
string.
5f481e4e888b 5f481e4e888b 22a3fa3c4254 beb4cbf30d00 22a3fa3c4254 22a3fa3c4254 e71216a16853 e71216a16853 e71216a16853 2cbdbf55ed99 e71216a16853 2cbdbf55ed99 bdd1ddd05b7c 03bbd33bc084 03bbd33bc084 5f481e4e888b 03bbd33bc084 03bbd33bc084 2cbdbf55ed99 e71216a16853 2cbdbf55ed99 e71216a16853 e71216a16853 5f481e4e888b 5f481e4e888b 5f481e4e888b 5f481e4e888b 154becd92f40 5f481e4e888b 64b1a2320bcb d95ea48af67b e69d34136be5 57caeb60c52b 8075ec3d0233 8b8edfc25856 e71216a16853 e71216a16853 e71216a16853 e71216a16853 e71216a16853 e71216a16853 2898ea3ff76c 2bb5e9ee49fe e71216a16853 e71216a16853 e71216a16853 e71216a16853 e71216a16853 e71216a16853 e71216a16853 e71216a16853 e71216a16853 e71216a16853 e71216a16853 e71216a16853 e71216a16853 2cbdbf55ed99 e71216a16853 2cbdbf55ed99 bb35ad076e2f bb35ad076e2f bb35ad076e2f bb35ad076e2f bbd499c7b55e 2bb5e9ee49fe aa17c7a1b8a5 bbd499c7b55e e71216a16853 beb4cbf30d00 beb4cbf30d00 e71216a16853 2cbdbf55ed99 bb35ad076e2f bb35ad076e2f bb35ad076e2f 8b8edfc25856 bb35ad076e2f 5262c498b3a0 9fd64dd2617d 5f481e4e888b fbbe80e3322b a60cd29ba7e2 5f481e4e888b 5f481e4e888b cc21a2b86a30 9472a0150bf0 5f481e4e888b a60cd29ba7e2 a60cd29ba7e2 a60cd29ba7e2 8b8edfc25856 | .. _index:
#######################
Kallithea Documentation
#######################
* :ref:`genindex`
* :ref:`search`
Readme
******
.. toctree::
:maxdepth: 1
readme
Administrator guide
*******************
**Installation and upgrade**
.. toctree::
:maxdepth: 1
overview
installation
installation_win
installation_win_old
installation_iis
installation_puppet
upgrade
**Setup and configuration**
.. toctree::
:maxdepth: 1
setup
administrator_guide/auth
administrator_guide/vcs_setup
usage/email
usage/customization
**Maintenance**
.. toctree::
:maxdepth: 1
usage/backup
usage/performance
usage/debugging
usage/troubleshooting
User guide
**********
.. toctree::
:maxdepth: 1
usage/general
usage/vcs_notes
usage/locking
usage/statistics
api/api
Developer guide
***************
.. toctree::
:maxdepth: 1
contributing
dev/translation
dev/dbmigrations
.. _virtualenv: http://pypi.python.org/pypi/virtualenv
.. _python: http://www.python.org/
.. _django: http://www.djangoproject.com/
.. _mercurial: https://www.mercurial-scm.org/
.. _bitbucket: http://bitbucket.org/
.. _subversion: http://subversion.tigris.org/
.. _git: http://git-scm.com/
.. _celery: http://celeryproject.org/
.. _Sphinx: http://sphinx.pocoo.org/
.. _vcs: http://pypi.python.org/pypi/vcs
|