@@ -82,6 +82,40 @@ public void testCreateNewConfig() throws IOException {
8282 Files .deleteIfExists (result .configPath ());
8383 }
8484
85+ /** TIKA-4834: the config docs permit comments; the merge step must not reject them. */
86+ @ Test
87+ public void testMergeWithCommentedConfig () throws IOException {
88+ String existingConfig = """
89+ // leading line comment
90+ {
91+ /* block comment */
92+ "fetchers": {
93+ "existing-fetcher": { // trailing comment
94+ "file-system-fetcher": {
95+ "basePath": "/existing/path"
96+ }
97+ }
98+ },
99+ "plugin-roots": "existing-plugins"
100+ }
101+ """ ;
102+ Path existingPath = tempDir .resolve ("commented-config.json" );
103+ Files .writeString (existingPath , existingConfig );
104+
105+ ConfigOverrides overrides = ConfigOverrides .builder ()
106+ .addFetcher ("new-fetcher" , "file-system-fetcher" , Map .of ("basePath" , "/new/path" ))
107+ .build ();
108+ ConfigMerger .MergeResult result = ConfigMerger .mergeOrCreate (existingPath , overrides );
109+
110+ // The merged file is plain JSON: readable by a strict mapper, content intact.
111+ JsonNode root = new ObjectMapper ().readTree (result .configPath ().toFile ());
112+ assertEquals ("/existing/path" , root .get ("fetchers" ).get ("existing-fetcher" )
113+ .get ("file-system-fetcher" ).get ("basePath" ).asText ());
114+ assertTrue (root .get ("fetchers" ).has ("new-fetcher" ));
115+ assertEquals ("existing-plugins" , root .get ("plugin-roots" ).asText ());
116+ Files .deleteIfExists (result .configPath ());
117+ }
118+
85119 @ Test
86120 public void testMergeWithExistingConfig () throws IOException {
87121 // Create existing config
0 commit comments