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

Bug dict default #159

Closed
Staruy opened this issue Nov 11, 2017 · 2 comments
Closed

Bug dict default #159

Staruy opened this issue Nov 11, 2017 · 2 comments

Comments

@Staruy
Copy link

Staruy commented Nov 11, 2017

CODE:

{% set a="1" %}
{% set b=b | default("2") %}
{% set c={"key": "value"} %}
{% set d=d | default({"key": "value"}) %}

Type: {{ type(a) }} - Value: {{ a }}
Type: {{ type(b) }} - Value: {{ b }}
Type: {{ type(c) }} - Value: {{ c }}
Type: {{ type(d) }} - Value: {{ d }}
Type: {{ type(c.key) }} - Value: {{ c.key }}
Type: {{ type(d.key) }} - Value: {{ d.key }}

OUTPUT:

Type: str - Value: 1
Type: str - Value: 2
Type: dict - Value: {key=value}
Type: str - Value: {key=value}
Type: str - Value: value
Type: null - Value: 

What the problem with the last output?

@boulter
Copy link
Contributor

boulter commented Nov 17, 2017

Hi @Staruy,

the default filter currently only supports strings as values. Since d is a string, it has no key attribute.

If you're interested in adding this feature, I'm happy to review a pull request!

@gabru-md
Copy link
Contributor

Hey @boulter , I would like to try my hands on this issue.
I'd really be happy to provide a PR for this, can you please brief me about the job to be done so that I can try it out? 😅

gabru-md added a commit to gabru-md/jinjava that referenced this issue Jan 15, 2020
boulter added a commit that referenced this issue Jan 17, 2020
Fixes #159: Adds dict support for DefaultFilter
boulter added a commit that referenced this issue Jan 17, 2020
Revert "Fixes #159: Adds dict support for DefaultFilter"
Joeoh added a commit that referenced this issue Feb 10, 2020
* First draft of deferring from tag including macros

* Checkstyle

* Add more tests

* Remove incorrect assert

* Add test that checks deferring macros in depth and update DeferredValue & MacroFunction

* Checkstyle

* Make constructor private and overload instance method

* Fixes #159: Adds dict support for DefaultFilter

* removes undesired code from Filter.java

* removes whitespaces from DateTimeFormatFilter.java

* Fixes Style Check Errors

* Removes stringArgs from DateTimeFormatFilter

* Revert "Fixes #159: Adds dict support for DefaultFilter"

* Changes DefaultFilter to extend AdvancedFilter

* adds PyList support to ForTag

* adds tests for ForTag

* removes escape filter from fortag test

* Fix resoncstruct end to honor trim tags

* Add reconstructImage to MacroFunction

* Add test for reconstructing macro with no trim tags

* Whitespace fix

* Implement safe filter as SafeString and handle SafeString in filters, functions and expressions (#385)

* Start implementing safe filter

* Remove comment about pass-through implementation

* Return var if it's not instance of string instead of throwing

* Add test for pass-through

* Add support for SafeString to all filters which handle Strings

* Remove utils for string reverse filter

* Handle SafeString in truncate function

* Formatting fix

* Add SafeStringFilter interface

* Handle safe strings in filters

* rm trailing space

* Formatting fixes

* Move safeFilter method to Filter IF and remove SafeFilter IF

* rm space

* Change behaviour of Urlize filter to not always return a SafeString

* Code style changes

* Remove unnecessary call to safeString

* Style fix

* Add tests to handle Urlize string being escaped and made safe

* rm hardcoded string

* rm uneeded getValue

* Add SafeString type as str

* Handle SafeString in expressions

Co-authored-by: Joe <[email protected]>

* Fix template error line numbers (#380)

* Fix line numbers

* add to some more places

* two levels deep test

* Fix case with child interpreter

* Add deprecation

* Add another test

* Update error messages

* Fix up error messages and tests

* Fix case with scopes

* Add check for inherit

* Put everything on the path stack

* always push parent

* remove callstack crud

* Set back path management

* Fix extend lineNo/position and keep track for each block

* cleanup

* Add test for extends

* Add more tests

* Check parent call stack for emtpy and line numbers

* Fix test

* Reorient line numbers when evaluating macros, make sure to pop import path off of stack

* Add test for imported macros

* Reorient line numbers when resolving blocks

* Reorient line numbers when processing extend parents

* Add tests for extends + includes

* Revert "Implement safe filter as SafeString and handle SafeString in filters, functions and expressions (#385)"

This reverts commit a6bea47.

* Implement safe filter as SafeString and handle SafeString in filters, functions and expressions (#394)

* Start implementing safe filter

* Remove comment about pass-through implementation

* Return var if it's not instance of string instead of throwing

* Add test for pass-through

* Handle safestrings and call implementor

* Add tests

* Handle SafeString in filter using kwargs

* Handle safe strings in most simple expressions

* Handle SafeString in IsUpperExp

* Handle SafeString in filters. Allow overriding from within filter

* Formatting fixes

Co-authored-by: jkollmann <[email protected]>

* First draft of deferring from tag including macros

* Checkstyle

* Add more tests

* Remove incorrect assert

* Add test that checks deferring macros in depth and update DeferredValue & MacroFunction

* Checkstyle

* Make constructor private and overload instance method

* Fix resoncstruct end to honor trim tags

* Add reconstructImage to MacroFunction

* Add test for reconstructing macro with no trim tags

* Whitespace fix

* rm duplicate statement after merge

Co-authored-by: Manish Devgan <[email protected]>
Co-authored-by: Jeff Boulter <[email protected]>
Co-authored-by: Joe <[email protected]>
Co-authored-by: Matt Coley <[email protected]>
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

Successfully merging a pull request may close this issue.

3 participants