Skip to content

Always pass a mutable keyword arguments hash to filters#88

Merged
dylanahsmith merged 1 commit into
masterfrom
no-const-kw-hash
Oct 14, 2020
Merged

Always pass a mutable keyword arguments hash to filters#88
dylanahsmith merged 1 commit into
masterfrom
no-const-kw-hash

Conversation

@dylanahsmith
Copy link
Copy Markdown
Contributor

Problem

While looking at application test failures for #60, I noticed a few FrozenError: can't modify frozen Hash exceptions in one of the filters. The filter was modifying the options hash that was passed to it.

Actually, the rb_hash_freeze(const_keyword_args); line in that PR (https://github.com/Shopify/liquid-c/pull/60/files#r504912592) is missing on master, but it is passing the same hash to filter call. That could result in even more subtle problems. As mentioned on the common for that line

I think we are going to have to always freeze or always dup the hash. Otherwise, it is too easy to test a filter using dynamic keyword arguments and then get errors in production when a frozen hash is passed in for constant keyword arguments.

Solution

Most filters take positional arguments, so it might not be worth trying to optimize for constant keyword arguments at the moment. So I've just removed that special case to make the code simpler, by always building a new hash for filter keyword arguments.

@dylanahsmith dylanahsmith merged commit aa0b3bf into master Oct 14, 2020
@dylanahsmith dylanahsmith deleted the no-const-kw-hash branch October 14, 2020 19:49
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 this pull request may close these issues.

2 participants