Add / as a valid partialNameChar and use it in parse (#71)

* Add / as a valid partialNameChar and use it in parse

* maybe let's not keep "bla" in the tests
This commit is contained in:
Ralph Kühnert
2025-08-30 17:13:26 +02:00
committed by GitHub
parent 28df3156e2
commit 6df64896f4
2 changed files with 4 additions and 4 deletions

View File

@@ -441,7 +441,7 @@ extension MustacheTemplate {
/// parse partial name /// parse partial name
static func parsePartialName(_ parser: inout Parser, state: ParserState) throws -> String { static func parsePartialName(_ parser: inout Parser, state: ParserState) throws -> String {
parser.read(while: \.isWhitespace) parser.read(while: \.isWhitespace)
let text = String(parser.read(while: self.sectionNameChars)) let text = String(parser.read(while: self.partialNameChars))
parser.read(while: \.isWhitespace) parser.read(while: \.isWhitespace)
guard try parser.read(string: state.endDelimiter) else { throw Error.unfinishedName } guard try parser.read(string: state.endDelimiter) else { throw Error.unfinishedName }
return text return text
@@ -518,5 +518,5 @@ extension MustacheTemplate {
private static let sectionNameCharsWithoutBrackets = Set<Character>("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_?*") private static let sectionNameCharsWithoutBrackets = Set<Character>("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_?*")
private static let sectionNameChars = Set<Character>("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_?()*") private static let sectionNameChars = Set<Character>("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_?()*")
private static let partialNameChars = Set<Character>("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_()") private static let partialNameChars = Set<Character>("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_?()*/")
} }

View File

@@ -23,7 +23,7 @@ final class PartialTests: XCTestCase {
string: """ string: """
<h2>Names</h2> <h2>Names</h2>
{{#names}} {{#names}}
{{> user}} {{> us/er}}
{{/names}} {{/names}}
""" """
) )
@@ -33,7 +33,7 @@ final class PartialTests: XCTestCase {
""" """
) )
let library = MustacheLibrary(templates: ["base": template, "user": template2]) let library = MustacheLibrary(templates: ["base": template, "us/er": template2])
let object: [String: Any] = ["names": ["john", "adam", "claire"]] let object: [String: Any] = ["names": ["john", "adam", "claire"]]
XCTAssertEqual( XCTAssertEqual(