Allow for space after value in {{%var:value}}

This commit is contained in:
Adam Fowler
2021-03-23 17:45:17 +00:00
parent d3edef1b8e
commit 40ef59c897
2 changed files with 7 additions and 0 deletions

View File

@@ -343,6 +343,7 @@ extension HBMustacheTemplate {
guard try parser.read(":") else { throw Error.invalidConfigVariableSyntax } guard try parser.read(":") else { throw Error.invalidConfigVariableSyntax }
parser.read(while: \.isWhitespace) parser.read(while: \.isWhitespace)
value = parser.read(while: self.sectionNameCharsWithoutBrackets) value = parser.read(while: self.sectionNameCharsWithoutBrackets)
parser.read(while: \.isWhitespace)
guard try parser.read(string: state.endDelimiter) else { throw Error.invalidConfigVariableSyntax } guard try parser.read(string: state.endDelimiter) else { throw Error.invalidConfigVariableSyntax }
} catch { } catch {
throw Error.invalidConfigVariableSyntax throw Error.invalidConfigVariableSyntax

View File

@@ -34,7 +34,13 @@ final class TemplateParserTests: XCTestCase {
func testContentType() throws { func testContentType() throws {
let template = try HBMustacheTemplate(string: "{{% CONTENT_TYPE:TEXT}}") 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(template.tokens, [.contentType(HBTextContentType())])
XCTAssertEqual(template1.tokens, [.contentType(HBTextContentType())])
XCTAssertEqual(template2.tokens, [.contentType(HBTextContentType())])
XCTAssertEqual(template3.tokens, [.contentType(HBTextContentType())])
} }
} }