@@ -181,3 +181,100 @@ def test_roundtrip_compatibility():
181181 assert parsed_post .metadata ["title" ] == original_post .metadata ["title" ]
182182 assert parsed_post .metadata ["tags" ] == original_post .metadata ["tags" ]
183183 assert parsed_post .metadata ["type" ] == original_post .metadata ["type" ]
184+
185+
186+ def test_title_with_colon ():
187+ """Test that titles with colons are properly quoted and don't break YAML parsing."""
188+ post = frontmatter .Post ("Test content" )
189+ post .metadata ["title" ] = "L2 Governance Core (Split: Core)"
190+ post .metadata ["type" ] = "note"
191+
192+ result = dump_frontmatter (post )
193+
194+ # PyYAML uses single quotes for values with special characters
195+ assert "title: 'L2 Governance Core (Split: Core)'" in result
196+
197+ # Should be parseable back
198+ parsed_post = frontmatter .loads (result )
199+ assert parsed_post .metadata ["title" ] == "L2 Governance Core (Split: Core)"
200+
201+
202+ def test_title_starting_with_word_and_colon ():
203+ """Test that titles starting with word and colon are properly quoted."""
204+ post = frontmatter .Post ("Test content" )
205+ post .metadata ["title" ] = "Governance: Rootkeeper Manifest-Diff Prompt"
206+ post .metadata ["type" ] = "note"
207+
208+ result = dump_frontmatter (post )
209+
210+ # PyYAML auto-quotes values with colons (uses single quotes by default)
211+ assert "title: 'Governance: Rootkeeper Manifest-Diff Prompt'" in result
212+
213+ # Should be parseable back
214+ parsed_post = frontmatter .loads (result )
215+ assert parsed_post .metadata ["title" ] == "Governance: Rootkeeper Manifest-Diff Prompt"
216+
217+
218+ def test_multiple_colons_in_title ():
219+ """Test that titles with multiple colons are properly quoted."""
220+ post = frontmatter .Post ("Test content" )
221+ post .metadata ["title" ] = "API: HTTP: Response Codes: Overview"
222+ post .metadata ["type" ] = "note"
223+
224+ result = dump_frontmatter (post )
225+
226+ # PyYAML auto-quotes values with colons
227+ assert "title: 'API: HTTP: Response Codes: Overview'" in result
228+
229+ # Should be parseable back
230+ parsed_post = frontmatter .loads (result )
231+ assert parsed_post .metadata ["title" ] == "API: HTTP: Response Codes: Overview"
232+
233+
234+ def test_other_special_characters_in_title ():
235+ """Test that titles with other special YAML characters are properly quoted."""
236+ special_chars_titles = [
237+ "Title with @ symbol" ,
238+ "Title with # hashtag" ,
239+ "Title with & ampersand" ,
240+ "Title with * asterisk" ,
241+ "Title [with brackets]" ,
242+ "Title {with braces}" ,
243+ "Title with | pipe" ,
244+ "Title with > greater" ,
245+ ]
246+
247+ for title in special_chars_titles :
248+ post = frontmatter .Post ("Test content" )
249+ post .metadata ["title" ] = title
250+ post .metadata ["type" ] = "note"
251+
252+ result = dump_frontmatter (post )
253+
254+ # Should be parseable without errors
255+ parsed_post = frontmatter .loads (result )
256+ assert parsed_post .metadata ["title" ] == title
257+
258+
259+ def test_all_string_values_quoted ():
260+ """Test that string values with special characters are automatically quoted."""
261+ post = frontmatter .Post ("Test content" )
262+ post .metadata ["title" ] = "Test: Title"
263+ post .metadata ["permalink" ] = "test-permalink"
264+ post .metadata ["type" ] = "note"
265+ post .metadata ["custom_field" ] = "value: with colon"
266+
267+ result = dump_frontmatter (post )
268+
269+ # PyYAML auto-quotes values with special chars, leaves simple values unquoted
270+ assert "title: 'Test: Title'" in result # Has colon, gets quoted
271+ assert "permalink: test-permalink" in result # Simple value, no quotes
272+ assert "type: note" in result # Simple value, no quotes
273+ assert "custom_field: 'value: with colon'" in result # Has colon, gets quoted
274+
275+ # Should be parseable back correctly
276+ parsed_post = frontmatter .loads (result )
277+ assert parsed_post .metadata ["title" ] == "Test: Title"
278+ assert parsed_post .metadata ["permalink" ] == "test-permalink"
279+ assert parsed_post .metadata ["type" ] == "note"
280+ assert parsed_post .metadata ["custom_field" ] == "value: with colon"
0 commit comments