@@ -71,6 +71,8 @@ fn check_loaded(filename: &Path, content: &[u8], allow_multi_docs: bool) -> Hook
7171 // high-reuse anchors that are common in compose-style files. See #1838.
7272 enforce_alias_anchor_ratio: false ,
7373 } ,
74+ // Comments do not affect syntax or structure validation. See #2501.
75+ emit_comments: false ,
7476 // Do not require `!!binary` scalars to decode as UTF-8. See #1102.
7577 ignore_binary_tag_for_string: true ,
7678 // The scalar values are discarded, so only validate whether they are
@@ -102,9 +104,15 @@ fn check_syntax(filename: &Path, content: &[u8]) -> HookOutput {
102104 }
103105 } ;
104106
107+ let options = granit_parser:: options! {
108+ // Comments do not affect syntax validation. See #2501.
109+ emit_comments: false ,
110+ } ;
111+
105112 // TODO: `granit-parser` resolves aliases while producing parser events, so this is stricter
106113 // than upstream's syntax-only mode for aliases that reference an undefined anchor.
107- for event in granit_parser:: Parser :: new_from_str ( content) {
114+ for event in granit_parser:: Parser :: with_options ( granit_parser:: StrInput :: new ( content) , options)
115+ {
108116 if let Err ( error) = event {
109117 let error_message = format ! ( "{}: Failed to yaml parse ({error})\n " , filename. display( ) ) ;
110118 return HookOutput :: unchanged ( 1 , error_message. into_bytes ( ) ) ;
@@ -346,4 +354,27 @@ response:
346354 assert ! ( result. output. is_empty( ) ) ;
347355 Ok ( ( ) )
348356 }
357+
358+ #[ tokio:: test]
359+ async fn test_yaml_with_many_consecutive_comments ( ) -> Result < ( ) > {
360+ let dir = tempdir ( ) ?;
361+ let mut content = "items:\n " . to_string ( ) ;
362+ for index in 0 ..100 {
363+ let _ = writeln ! ( content, " # comment {index}" ) ;
364+ }
365+ content. push_str ( " - value\n " ) ;
366+
367+ let file_path = create_test_file ( & dir, "many-comments.yaml" , content. as_bytes ( ) ) . await ?;
368+ for mode in [ LOAD_SINGLE_DOCUMENT , CheckMode :: SyntaxOnly ] {
369+ let result = check_file ( Path :: new ( "" ) , & file_path, mode) . await ?;
370+ assert_eq ! (
371+ result. exit_status,
372+ 0 ,
373+ "{}" ,
374+ String :: from_utf8_lossy( & result. output)
375+ ) ;
376+ assert ! ( result. output. is_empty( ) ) ;
377+ }
378+ Ok ( ( ) )
379+ }
349380}
0 commit comments