From 40ef59c897e9292134200fc652dcb98417ff1bb5 Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Tue, 23 Mar 2021 17:45:17 +0000 Subject: [PATCH] Allow for space after value in {{%var:value}} --- Sources/HummingbirdMustache/Template+Parser.swift | 1 + Tests/HummingbirdMustacheTests/TemplateParserTests.swift | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/Sources/HummingbirdMustache/Template+Parser.swift b/Sources/HummingbirdMustache/Template+Parser.swift index 72ceb7e..4d7e0f9 100644 --- a/Sources/HummingbirdMustache/Template+Parser.swift +++ b/Sources/HummingbirdMustache/Template+Parser.swift @@ -343,6 +343,7 @@ extension HBMustacheTemplate { guard try parser.read(":") else { throw Error.invalidConfigVariableSyntax } parser.read(while: \.isWhitespace) value = parser.read(while: self.sectionNameCharsWithoutBrackets) + parser.read(while: \.isWhitespace) guard try parser.read(string: state.endDelimiter) else { throw Error.invalidConfigVariableSyntax } } catch { throw Error.invalidConfigVariableSyntax diff --git a/Tests/HummingbirdMustacheTests/TemplateParserTests.swift b/Tests/HummingbirdMustacheTests/TemplateParserTests.swift index 83b9587..f7e7f08 100644 --- a/Tests/HummingbirdMustacheTests/TemplateParserTests.swift +++ b/Tests/HummingbirdMustacheTests/TemplateParserTests.swift @@ -34,7 +34,13 @@ final class TemplateParserTests: XCTestCase { func testContentType() throws { let template = try HBMustacheTemplate(string: "{{% CONTENT_TYPE:TEXT}}") + let template1 = try HBMustacheTemplate(string: "{{% CONTENT_TYPE:TEXT }}") + let template2 = try HBMustacheTemplate(string: "{{% CONTENT_TYPE: TEXT}}") + let template3 = try HBMustacheTemplate(string: "{{%CONTENT_TYPE:TEXT}}") XCTAssertEqual(template.tokens, [.contentType(HBTextContentType())]) + XCTAssertEqual(template1.tokens, [.contentType(HBTextContentType())]) + XCTAssertEqual(template2.tokens, [.contentType(HBTextContentType())]) + XCTAssertEqual(template3.tokens, [.contentType(HBTextContentType())]) } }