Skip to content

Commit d3bbb4f

Browse files
authored
String indexer should return nil (#540)
Fixes #539
1 parent 934e395 commit d3bbb4f

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

Fluid.Tests/TemplateTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,14 +364,14 @@ public async Task ShouldOnlyAllowInheritedMember()
364364
}
365365

366366
[Fact]
367-
public async Task ShouldEvaluateStringIndex()
367+
public async Task StringIndexerReturnsNil()
368368
{
369-
_parser.TryParse("{{ x[1] }}", out var template, out var error);
369+
_parser.TryParse("{% if x[0] == blank %}true{% else %}false{% endif %}", out var template, out var error);
370370
var context = new TemplateContext();
371371
context.SetValue("x", "abc");
372372

373373
var result = await template.RenderAsync(context);
374-
Assert.Equal("b", result);
374+
Assert.Equal("true", result);
375375
}
376376

377377
[Fact]

Fluid/Values/StringValue.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,7 @@ public override bool Equals(FluidValue other)
103103

104104
protected override FluidValue GetIndex(FluidValue index, TemplateContext context)
105105
{
106-
var i = (int) index.ToNumberValue();
107-
108-
if (i < _value.Length)
109-
{
110-
return Create(_value[i]);
111-
}
112-
106+
// Indexer on string values should return nil.
113107
return NilValue.Instance;
114108
}
115109

0 commit comments

Comments
 (0)