[GH-ISSUE #2942] [Issue]: {{#if}} number comparisons (> < >= <=) silently don't work and always pass #1520

Closed
opened 2026-10-21 05:37:52 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 28, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2942

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

{{#if}} only understands ==, !=, =, is, is not, contains, includes. Number comparisons like >, <, >=, <= are not supported — but instead of erroring, the condition silently falls back to "is this non-empty?", which is almost always true. So a condition the author expects to be false (e.g. {{#if 3 > 5}}) quietly passes and the wrong text is shown.

Also note == compares as lowercased strings, not numbers, so {{#if 5 == 5.0}} is false.

How to reproduce (try it yourself)

Put this in a character field, lorebook entry, or preset:

{{#if 1 > 100}}THIS SHOULD NOT SHOW{{/if}}

You'll see: THIS SHOULD NOT SHOW appears in the prompt.
Expected: nothing (1 is not greater than 100).

Where it is

packages/shared/src/utils/macro-engine.ts — parseConditionExpression (line 512) lists the supported operators; > < >= <= aren't in it, so the whole expression becomes the "truthy" case in evaluateCondition (line 553). compareConditionValues (531) only does string equality/contains, never numeric comparison.

What's happening

The operator regex doesn't include the comparison operators, so 3 > 5 isn't parsed as a comparison at all — it's treated as a single value and checked for non-emptiness, which passes.

Suggested fix

Either add real numeric comparison support (> < >= <=, comparing as numbers when both sides are numeric), or — if comparisons are intentionally unsupported — make an unrecognized operator evaluate to false (or leave the block unrendered) rather than silently truthy, so authors notice. Document which operators are supported.


Found by a code review of v2.0.6; please verify the reproduction before fixing.

Originally created by @kolacheee on GitHub (Jun 28, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2942 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** `{{#if}}` only understands `==`, `!=`, `=`, `is`, `is not`, `contains`, `includes`. Number comparisons like `>`, `<`, `>=`, `<=` are **not** supported — but instead of erroring, the condition silently falls back to "is this non-empty?", which is almost always true. So a condition the author expects to be false (e.g. `{{#if 3 > 5}}`) quietly passes and the wrong text is shown. Also note `==` compares as **lowercased strings**, not numbers, so `{{#if 5 == 5.0}}` is false. **How to reproduce (try it yourself)** Put this in a character field, lorebook entry, or preset: ``` {{#if 1 > 100}}THIS SHOULD NOT SHOW{{/if}} ``` **You'll see:** `THIS SHOULD NOT SHOW` appears in the prompt. **Expected:** nothing (1 is not greater than 100). **Where it is** `packages/shared/src/utils/macro-engine.ts` — `parseConditionExpression` (line 512) lists the supported operators; `>` `<` `>=` `<=` aren't in it, so the whole expression becomes the "truthy" case in `evaluateCondition` (line 553). `compareConditionValues` (531) only does string equality/contains, never numeric comparison. **What's happening** The operator regex doesn't include the comparison operators, so `3 > 5` isn't parsed as a comparison at all — it's treated as a single value and checked for non-emptiness, which passes. **Suggested fix** Either add real numeric comparison support (`>` `<` `>=` `<=`, comparing as numbers when both sides are numeric), or — if comparisons are intentionally unsupported — make an unrecognized operator evaluate to **false** (or leave the block unrendered) rather than silently truthy, so authors notice. Document which operators are supported. --- *Found by a code review of v2.0.6; please verify the reproduction before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 28, 2026):

Addressed in the staging fixes: {{#if}} now recognizes >, <, >=, and <= operators and compares numerically when both sides are numbers, including numeric equality such as 5 == 5.0. Regression coverage was added for false and true numeric branches.

<!-- gh-comment-id:4827517847 --> @SpicyMarinara commented on GitHub (Jun 28, 2026): Addressed in the staging fixes: {{#if}} now recognizes >, <, >=, and <= operators and compares numerically when both sides are numbers, including numeric equality such as 5 == 5.0. Regression coverage was added for false and true numeric branches.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1520
No description provided.