@@ -60,7 +60,7 @@ describe("json", function () {
6060 createMockedJsonKeyValue ( "json.settings.object" , "{}" ) ,
6161 createMockedJsonKeyValue ( "json.settings.array" , "[]" ) ,
6262 createMockedJsonKeyValue ( "json.settings.number" , "8" ) ,
63- createMockedJsonKeyValue ( "json.settings.string" , "string" ) ,
63+ createMockedJsonKeyValue ( "json.settings.string" , "\" string\" " ) ,
6464 createMockedJsonKeyValue ( "json.settings.false" , "false" ) ,
6565 createMockedJsonKeyValue ( "json.settings.true" , "true" ) ,
6666 createMockedJsonKeyValue ( "json.settings.null" , "null" ) ,
@@ -88,4 +88,87 @@ describe("json", function () {
8888 expect ( settings . get ( "json.settings.emptyString" ) ) . eq ( "" , "is empty string" ) ;
8989 expect ( settings . get ( "json.settings.illegalString" ) ) . eq ( "[unclosed" , "is illegal string" ) ;
9090 } ) ;
91+
92+ it ( "should load json values with comments" , async ( ) => {
93+ // Test various comment styles and positions
94+ const mixedCommentStylesValue = `{
95+ // Single line comment at start
96+ "ApiSettings": {
97+ "BaseUrl": "https://api.example.com", // Inline single line
98+ /* Multi-line comment
99+ spanning multiple lines */
100+ "ApiKey": "secret-key",
101+ "Endpoints": [
102+ // Comment before array element
103+ "/users",
104+ /* Comment between elements */
105+ "/orders",
106+ "/products" // Comment after element
107+ ]
108+ },
109+ // Test edge cases
110+ "StringWithSlashes": "This is not a // comment",
111+ "StringWithStars": "This is not a /* comment */",
112+ "UrlValue": "https://example.com/path", // This is a real comment
113+ "EmptyComment": "value", //
114+ /**/
115+ "AfterEmptyComment": "value2"
116+ /* Final multi-line comment */
117+ }` ;
118+
119+ // Test invalid JSON with comments
120+ const invalidJsonWithCommentsValue = `// This is a comment
121+ { invalid json structure
122+ // Another comment
123+ missing quotes and braces` ;
124+
125+ // Test only comments (should be invalid JSON)
126+ const onlyCommentsValue = `
127+ // Just comments
128+ /* No actual content */
129+ ` ;
130+
131+ const keyValues = [
132+ createMockedJsonKeyValue ( "MixedCommentStyles" , mixedCommentStylesValue ) ,
133+ createMockedJsonKeyValue ( "InvalidJsonWithComments" , invalidJsonWithCommentsValue ) ,
134+ createMockedJsonKeyValue ( "OnlyComments" , onlyCommentsValue )
135+ ] ;
136+
137+ mockAppConfigurationClientListConfigurationSettings ( [ keyValues ] ) ;
138+
139+ const connectionString = createMockedConnectionString ( ) ;
140+ const settings = await load ( connectionString ) ;
141+ expect ( settings ) . not . undefined ;
142+
143+ // Verify mixed comment styles are properly parsed
144+ const mixedConfig = settings . get < any > ( "MixedCommentStyles" ) ;
145+ expect ( mixedConfig ) . not . undefined ;
146+ expect ( mixedConfig . ApiSettings ) . not . undefined ;
147+ expect ( mixedConfig . ApiSettings . BaseUrl ) . eq ( "https://api.example.com" ) ;
148+ expect ( mixedConfig . ApiSettings . ApiKey ) . eq ( "secret-key" ) ;
149+ expect ( mixedConfig . ApiSettings . Endpoints ) . not . undefined ;
150+ expect ( Array . isArray ( mixedConfig . ApiSettings . Endpoints ) ) . eq ( true ) ;
151+ expect ( mixedConfig . ApiSettings . Endpoints [ 0 ] ) . eq ( "/users" ) ;
152+ expect ( mixedConfig . ApiSettings . Endpoints [ 1 ] ) . eq ( "/orders" ) ;
153+ expect ( mixedConfig . ApiSettings . Endpoints [ 2 ] ) . eq ( "/products" ) ;
154+
155+ // Verify edge cases where comment-like text appears in strings
156+ expect ( mixedConfig . StringWithSlashes ) . eq ( "This is not a // comment" ) ;
157+ expect ( mixedConfig . StringWithStars ) . eq ( "This is not a /* comment */" ) ;
158+ expect ( mixedConfig . UrlValue ) . eq ( "https://example.com/path" ) ;
159+ expect ( mixedConfig . EmptyComment ) . eq ( "value" ) ;
160+ expect ( mixedConfig . AfterEmptyComment ) . eq ( "value2" ) ;
161+
162+ // Invalid JSON should fall back to string value
163+ const invalidConfig = settings . get ( "InvalidJsonWithComments" ) ;
164+ expect ( invalidConfig ) . not . undefined ;
165+ expect ( typeof invalidConfig ) . eq ( "string" ) ;
166+ expect ( invalidConfig ) . eq ( invalidJsonWithCommentsValue ) ;
167+
168+ // Only comments should be treated as string value (invalid JSON)
169+ const onlyCommentsConfig = settings . get ( "OnlyComments" ) ;
170+ expect ( onlyCommentsConfig ) . not . undefined ;
171+ expect ( typeof onlyCommentsConfig ) . eq ( "string" ) ;
172+ expect ( onlyCommentsConfig ) . eq ( onlyCommentsValue ) ;
173+ } ) ;
91174} ) ;
0 commit comments