Custom Liquid tags often add a trailing space to their arguments
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 11.9k
- Forks
- 1.5k
- Avg merge
- 17h 55m
- Merged PRs (30d)
- 3
Description
@jonniesweb and I are working on some custom Liquid tags for a site that can divide a section of content into small chunks, each of which has a button you can click to view that section of content. We use it to separate different sets of instructions by device (so we don't have to show instructions for desktop, iOS, and Android at the same time). It's kind of like a tabbed carousel.
Our tag looks like this:
{% sections Desktop, iOS, Android %}
Content for desktop only
----
Content for iOS only
----
Content for Android only
{% endsections %}
We pass a list of the device types as an argument and split it by commas.
The Liquid for Programmers wiki article says that arguments are passed to the tag "as a single string" which is true and works fine but this string includes the space before the tag termination pattern %}.
So when my tag is written {% sections Desktop, iOS, Android %}, the argument that gets passed is 'Desktop, iOS, Android ', with a trailing space. Liquid is interpreting the single space following "Android" as part of the argument, and as a result I need to #strip my argument string before I do anything with it. This seems like it shouldn't be happening.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file or test is named. Reproduce the custom tag example and trace how tag arguments are parsed, checking where the space before %} is retained. Done means the argument no longer includes that trailing space and the behavior is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100