Spaces between argument separator and argument in template filter generate error

151 Aufrufe
Direkt zur ersten ungelesenen Nachricht

oli...@kidsnote.com

ungelesen,
30.05.2018, 22:41:2230.05.18
an Django developers (Contributions to Django itself)
In the template filter system now,
spaces between augment separator and augments generate error.
For example, the following template code generates the following error.
{{ value | filter: "arg"}}
TemplateSyntaxError at /
Could not parse the remainder: ': "arg"' from 'value | filter: "arg"'
https://code.djangoproject.com/ticket/29457

What do you think of this ticket?

Adam Johnson

ungelesen,
31.05.2018, 06:22:5231.05.18
an django-d...@googlegroups.com
I think it's better to be conservative here and leave it as-is, the current syntax has worked for years and this change doesn't really reduce the risk of bugs.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/41376429-949c-4202-9074-5dc0200fc8ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Adam

oli...@kidsnote.com

ungelesen,
31.05.2018, 07:11:1231.05.18
an Django developers (Contributions to Django itself)
Are there any reasons that not allow spaces between separator and arg?

2018년 5월 31일 목요일 오전 11시 41분 22초 UTC+9, oli...@kidsnote.com 님의 말:

James Bennett

ungelesen,
31.05.2018, 07:40:5831.05.18
an django-d...@googlegroups.com
On Thu, May 31, 2018 at 1:39 AM, <oli...@kidsnote.com> wrote:
Are there any reasons that not allow spaces between separator and arg?

Every optional variant of template syntax is a potential source of bugs or compatibility issues for the future. And a potential source of confusion when someone is trying to learn by reading code -- why did one developer do it *this* way, while another developer did it *that* way? And another choice every dev team has to make when putting together their style guide, and another option they have to set on their linters, to make sure they get a consistent codebase.

For these reasons, the default position should be "don't add it unless there's a very good reason to". If there is a good reason to add it, please explain so we can understand why you're requesting it.

oli...@kidsnote.com

ungelesen,
31.05.2018, 20:59:1431.05.18
an Django developers (Contributions to Django itself)
Thank you for your reply.
I understand your opinion well


2018년 5월 31일 목요일 오전 11시 41분 22초 UTC+9, oli...@kidsnote.com 님의 말:
In the template filter system now,

Collin Anderson

ungelesen,
31.05.2018, 22:06:0131.05.18
an django-d...@googlegroups.com
Maybe it would be worth having a more friendly error message?

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.

Alasdair Nicol

ungelesen,
01.06.2018, 04:59:0301.06.18
an Django developers (Contributions to Django itself)
On Friday, 1 June 2018 03:06:01 UTC+1, Collin Anderson wrote:
Maybe it would be worth having a more friendly error message?


I agree, it would be good to improve the message.

I've also seen users confused by the "could not parse the remainder" message when they forget the spaces around boolean operators, for example:

    {% if foo=='bar' %}

On Thu, May 31, 2018 at 8:59 PM, <oli...@kidsnote.com> wrote:
Thank you for your reply.
I understand your opinion well

2018년 5월 31일 목요일 오전 11시 41분 22초 UTC+9, oli...@kidsnote.com 님의 말:
In the template filter system now,
spaces between augment separator and augments generate error.
For example, the following template code generates the following error.
{{ value | filter: "arg"}}
TemplateSyntaxError at /
Could not parse the remainder: ': "arg"' from 'value | filter: "arg"'
https://code.djangoproject.com/ticket/29457

What do you think of this ticket?

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.

Curtis Maloney

ungelesen,
01.06.2018, 06:21:1201.06.18
an django-d...@googlegroups.com
On 05/31/2018 06:39 PM, oli...@kidsnote.com wrote:
> Are there any reasons that not allow spaces between separator and arg?

My first thought would be that it starts making the syntax looser,
meaning more things that are currently error cases would be accepted as
valid.

Which means mistakes will no longer raise errors.

--
Curtis


> 2018년 5월 31일 목요일 오전 11시 41분 22초 UTC+9, oli...@kidsnote.com
> 의 말:
>
> In the template filter system now,
>
> spaces between augment separator and augments generate error.
> For example, the following template code generates the following error.
>
> {{ value | filter: "arg"}}
>
> TemplateSyntaxError at /
> Could not parse the remainder: ': "arg"' from 'value | filter: "arg"'
>
> https://code.djangoproject.com/ticket/29457
> <https://code.djangoproject.com/ticket/29457>
>
>
> What do you think of this ticket?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-develop...@googlegroups.com
> <mailto:django-develop...@googlegroups.com>.
> To post to this group, send email to django-d...@googlegroups.com
> <mailto:django-d...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-developers.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/131b5095-c5b7-4492-92fa-e58912ac842a%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/131b5095-c5b7-4492-92fa-e58912ac842a%40googlegroups.com?utm_medium=email&utm_source=footer>.
Die Nachricht wurde gelöscht
Die Nachricht wurde gelöscht

oli...@kidsnote.com

ungelesen,
04.06.2018, 22:17:5104.06.18
an Django developers (Contributions to Django itself)
Currently, spaces between filter separator( | ) and filter name is allowed. Also, value name and filter separator.
So, following is allowed.

    {{ value    |    filter:"arg" }}
    {{ value|filter:"arg" }}

But, following is not allowed.

    {{ value|filter: "arg" }}

users are confused by the inconsistency. 

I think that either the error message or syntax should be improved.
Die Nachricht wurde gelöscht

oli...@kidsnote.com

ungelesen,
04.06.2018, 22:30:0304.06.18
an Django developers (Contributions to Django itself)
filter_raw_string = r"""
^(?P<constant>%(constant)s)|
^(?P<var>[%(var_chars)s]+|%(num)s)|
(?:\s*%(filter_sep)s\s*
(?P<filter_name>\w+)
(?:%(arg_sep)s
(?:
(?P<constant_arg>%(constant)s)|
(?P<var_arg>[%(var_chars)s]+|%(num)s)
)
)?
)""" % {
'constant': constant_string,
'num': r'[-+\.]?\d[\d\.e]*',
'var_chars': r'\w\.',
'filter_sep': re.escape(FILTER_SEPARATOR),
'arg_sep': re.escape(FILTER_ARGUMENT_SEPARATOR),
}

allowing spaces can be done by simply adding \s* after (arg_sep)s

Florian Apolloner

ungelesen,
06.06.2018, 05:03:4806.06.18
an Django developers (Contributions to Django itself)


On Tuesday, June 5, 2018 at 4:30:03 AM UTC+2, oli...@kidsnote.com wrote:
allowing spaces can be done by simply adding \s* after (arg_sep)s

\s is __not__ the regex for spaces

oli...@kidsnote.com

ungelesen,
06.06.2018, 22:44:4306.06.18
an Django developers (Contributions to Django itself)
Sorry my mistake. It means white spaces  character not spaces

2018년 6월 6일 수요일 오후 6시 3분 48초 UTC+9, Florian Apolloner 님의 말:
Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten