Shopify / Shopify/liquid

Comparison operators are whitespace-sensitive

Open
#635 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Report Parser
Dominant language
Ruby
Stars
11.9k
Forks
1.5k
Avg merge
17h 55m
Merged PRs (30d)
3

Description

I was messing around in Jekyll with Liquid and discovered this weird behaviour when I hit auto-format on an HTML file:

{% assign foo = "bar" %}
{% if foo == "bar" %}
  true
{% else %}
  false
{% endif %}

gives the result true, whereas

{% assign foo = "bar" %}
{% if foo=="bar" %}
  true
{% else %}
  false
{% endif %}

gives the result false.

Furthermore,

{% assign foo = "" %}
{% if foo=="bar" %}
  true
{% else %}
  false
{% endif %}

gives the result true, as though Liquid is evaluating against the empty string.

Can anyone replicate this? Is this documented (and I missed it)? I can't seem to find any notes on how whitespace is relevant to Liquid, and I would expect it to obey the same whitespace rules as HTML (ie. ignore all unnecessary whitespace).
#428 relevant?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the two Liquid snippets to confirm how whitespace changes comparison results, then trace the comparison parsing path in the Liquid implementation. Done means comparisons behave consistently regardless of optional surrounding whitespace, with regression coverage for the shown cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.