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

Empty map in strict mode does not throw exception #491

Closed
BreadAndRoses95 opened this issue Dec 18, 2019 · 2 comments
Closed

Empty map in strict mode does not throw exception #491

BreadAndRoses95 opened this issue Dec 18, 2019 · 2 comments
Milestone

Comments

@BreadAndRoses95
Copy link

Hi, I'm currently using Pebble Version: 3.1.2 in strict mode.
When using a map as context, I was expecting an AttributeNotFoundException if the map was empty, in this case It just resolved to null. I think the expected behavior in strict mode would be to throw an Exception every time the key is not present, even if the map is actually empty.

A quick fix to this would be to move this part:

if(context.isStrictVariables() && !object.containsKey(key)) {
      throw new AttributeNotFoundException(null, String.format(
          "Attribute [%s] of [%s] does not exist or can not be accessed and strict variables is set to true.",
          attributeNameValue.toString(), object.getClass().getName()),
          attributeNameValue.toString(), lineNumber, filename);
    }

above this part

  if (object.isEmpty()) {
      return new ResolvedAttribute(null);
    }

Thank you !

@ebussieres
Copy link
Member

Fixed in next version

@BreadAndRoses95
Copy link
Author

BreadAndRoses95 commented Dec 19, 2019

Thanks for the reactivity 👍

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