@@ -452,6 +452,52 @@ def test_load_config_file_encoding_utf8(self):
452452 self .assertEqual (loaded_config ["symbols" ], "αβγδε" )
453453 self .assertEqual (loaded_config ["emoji" ], "🌍🔧⚡" )
454454
455+ def test_load_config_json_with_hash_comments (self ):
456+ """测试加载带有 # 注释的JSON配置文件"""
457+ json_with_comments = """{
458+ # Configuration for DDNS
459+ "dns": "cloudflare", # DNS provider
460+ "id": "test@example.com",
461+ "token": "secret123", # API token
462+ "ttl": 300
463+ # End of config
464+ }"""
465+ file_path = self .create_test_file ("test_hash_comments.json" , json_with_comments )
466+
467+ config = load_config (file_path )
468+
469+ expected = {"dns" : "cloudflare" , "id" : "test@example.com" , "token" : "secret123" , "ttl" : 300 }
470+ self .assertEqual (config , expected )
471+
472+ def test_load_config_json_with_double_slash_comments (self ):
473+ """测试加载带有 // 注释的JSON配置文件"""
474+ json_with_comments = """{
475+ // Configuration for DDNS
476+ "$schema": "https://ddns.newfuture.cc/schema/v4.0.json", // Schema validation
477+ "debug": false, // false=disable, true=enable
478+ "dns": "dnspod_com", // DNS provider
479+ "id": "1008666",
480+ "token": "ae86$cbbcctv666666666666666", // API Token
481+ "ipv4": ["test.lorzl.ml"], // IPv4 domains
482+ "ipv6": ["test.lorzl.ml"], // IPv6 domains
483+ "proxy": null // Proxy settings
484+ }"""
485+ file_path = self .create_test_file ("test_double_slash_comments.json" , json_with_comments )
486+
487+ config = load_config (file_path )
488+
489+ expected = {
490+ "$schema" : "https://ddns.newfuture.cc/schema/v4.0.json" ,
491+ "debug" : False ,
492+ "dns" : "dnspod_com" ,
493+ "id" : "1008666" ,
494+ "token" : "ae86$cbbcctv666666666666666" ,
495+ "ipv4" : ["test.lorzl.ml" ],
496+ "ipv6" : ["test.lorzl.ml" ],
497+ "proxy" : None ,
498+ }
499+ self .assertEqual (config , expected )
500+
455501 def test_save_config_pretty_format (self ):
456502 """Test that saved JSON is properly formatted"""
457503 config_data = {"dns" : "cloudflare" , "log_level" : "DEBUG" , "log_file" : "/var/log/ddns.log" }
0 commit comments