MCPcopy
hub / github.com/claude-code-best/claude-code / quoteProblematicValues

Function quoteProblematicValues

src/utils/frontmatterParser.ts:85–121  ·  view source on GitHub ↗

* Pre-processes frontmatter text to quote values that contain special YAML characters. * This allows glob patterns like **\/*.{ts,tsx} to be parsed correctly.

(frontmatterText: string)

Source from the content-addressed store, hash-verified

83 * This allows glob patterns like **\/*.{ts,tsx} to be parsed correctly.
84 */
85function quoteProblematicValues(frontmatterText: string): string {
86 const lines = frontmatterText.split('\n')
87 const result: string[] = []
88
89 for (const line of lines) {
90 // Match simple key: value lines (not indented, not list items, not block scalars)
91 const match = line.match(/^([a-zA-Z_-]+):\s+(.+)$/)
92 if (match) {
93 const [, key, value] = match
94 if (!key || !value) {
95 result.push(line)
96 continue
97 }
98
99 // Skip if already quoted
100 if (
101 (value.startsWith('"') && value.endsWith('"')) ||
102 (value.startsWith("'") && value.endsWith("'"))
103 ) {
104 result.push(line)
105 continue
106 }
107
108 // Quote if contains special YAML characters
109 if (YAML_SPECIAL_CHARS.test(value)) {
110 // Use double quotes and escape any existing double quotes
111 const escaped = value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')
112 result.push(`${key}: "${escaped}"`)
113 continue
114 }
115 }
116
117 result.push(line)
118 }
119
120 return result.join('\n')
121}
122
123export const FRONTMATTER_REGEX = /^---\s*\n([\s\S]*?)---\s*\n?/
124

Callers 1

parseFrontmatterFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected