﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
3838	stringformat filter allows trailing non-format characters but not leading characters	msimoens@…	nobody	"This filter seems to provide an, intentionally simplified, implementation of python's format strings. I'm not sure what the intent was with this simplification, however it is inconsistent. Due to the requirement that the preceding '%' be left out, one cannot put leading constant characters into the format string (which may be intended).  However, one _can_ put trailing constant characters into the format string and it will still work.  For instance:

{{{
{# fails #}
{{ generic_key_type|stringformat:""course/%s.html"" }} 

{# works #}
{{ generic_key_type|stringformat:""s/course/index.html"" }} 


}}}


The first way will not work, however the second way will work, which is inconsistent.  Either the filter should ensure that no trailing constant characters are used or it should allow both ways. If the intent is to simplify it in some way, then it should consistently not allow either trailing or leading characters. In this case, the name is very misleading as the filter is not equivalent to python's format strings, and I would argue that it should be renamed after the subset of functionality that it is intended to provide.

With its current name, I would argue that it should allow both trailing and leading characters, and the following is an implementation that allows this, and attempts to remain backwards compatible. 


{{{
def stringformat(value, arg):
    """"""
    Formats the variable according to the argument, a string formatting specifier.
    This specifier uses Python string formating syntax with the exception that
    the leading ""%"" may be dropped.

    See http://docs.python.org/lib/typesseq-strings.html for documentation
    of Python string formatting
    """"""
    
    try:
        return (""%"" + str(arg)) % value
    except (ValueError, TypeError):
        try: 
            return str(arg) % value
        except (ValueError, TypeError):
            return """"
}}}
"		closed	Template system	dev		wontfix	stringformat	msimoens@… lakin.wecker@… jm.bugtracking@…	Design decision needed	1	0	0	0	0	0
