This commit is contained in:
Łukasz Kuczborski
2021-04-09 23:21:46 +02:00
parent 7c635975d1
commit 61919c5e8e
2 changed files with 6 additions and 2 deletions

View File

@@ -49,6 +49,9 @@ _None_
- Throw syntax error on empty variable tags (`{{ }}`) instead `fatalError`.
[Ilya Puchka](https://github.com/ilyapuchka)
[#263](https://github.com/stencilproject/Stencil/pull/263)
- Fix for crashing range indexes when variable length is 1.
[Łukasz Kuczborski](https://github.com/lkuczborski)
[#306](https://github.com/stencilproject/Stencil/pull/306)
### Internal Changes

View File

@@ -48,10 +48,11 @@ public struct Variable: Equatable, Resolvable {
/// Resolve the variable in the given context
public func resolve(_ context: Context) throws -> Any? {
if (variable.hasPrefix("'") && variable.hasSuffix("'")) || (variable.hasPrefix("\"") && variable.hasSuffix("\"")) {
if variable.count > 1 && (variable.hasPrefix("'") && variable.hasSuffix("'")) || (variable.hasPrefix("\"") && variable.hasSuffix("\"")) {
// String literal
guard variable.count > 1 else { return "" }
return String(variable[variable.index(after: variable.startIndex) ..< variable.index(before: variable.endIndex)])
} else {
return ""
}
// Number literal