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

SIGABRT crash with key value coding #231

Closed
mbrandonw opened this issue Sep 9, 2018 · 2 comments
Closed

SIGABRT crash with key value coding #231

mbrandonw opened this issue Sep 9, 2018 · 2 comments

Comments

@mbrandonw
Copy link

Hi! I noticed that if you reference a field for a variable that doesn't exist, you get a crash with SIGABRT. For example this template render:

try Template(templateString: "{{ user.name }}").render(["user": "Blob"])

will crash.

To fix I believe all you have to do is guard this value(forKey:) call:

current = object.value(forKey: bit)

with this:

        if object.responds(to: Selector(bit)) {
          current = object.value(forKey: bit)
        }

Does the current code work as expected, or is it worth fixing?

Thanks!

@ilyapuchka
Copy link
Collaborator

@mbrandonw I was looking for that the whole day since read your article, but didn't realise that one could use selector for that. I'm not sure it would work though with custom property accessors and instance variables, didn't do ObjC for a while, but that should be rare anyway. Thanks for the tip, I'll make a PR. I suppose we will just return nil for now, but can consider better options later in general.

@mbrandonw
Copy link
Author

Cool, thanks for looking into it! FWIW I did that because I found it in the docs:

https://stencil.fuller.li/en/latest/templates.html#variables

[
  "item": [
    "name": "John"
  ],
  "key": "name"
]

"The result of {{ item[key] }} will be the same as {{ item.name }}. It will first evaluate the result of {{ key }}, and only then evaluate the lookup expression."

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