|
4 | 4 | import org.junit.jupiter.api.Test; |
5 | 5 | import org.junit.jupiter.params.ParameterizedTest; |
6 | 6 | import org.junit.jupiter.params.provider.Arguments; |
| 7 | +import org.junit.jupiter.params.provider.CsvSource; |
7 | 8 | import org.junit.jupiter.params.provider.MethodSource; |
8 | 9 | import org.junitpioneer.jupiter.SetSystemProperty; |
9 | 10 | import org.mockito.MockedStatic; |
@@ -179,7 +180,8 @@ public void testEscapeNameLegacy( |
179 | 180 | @SetSystemProperty(key = "io.prometheus.naming.validationScheme", value = "utf-8") |
180 | 181 | @ParameterizedTest |
181 | 182 | @MethodSource("escapeNameUtf8TestCases") |
182 | | - public void testEscapeNameUtf8(String input, EscapingScheme escapingScheme, String expected, String unescapeExpected) { |
| 183 | + public void testEscapeNameUtf8( |
| 184 | + String input, EscapingScheme escapingScheme, String expected, String unescapeExpected) { |
183 | 185 | PrometheusNaming.resetForTest(); |
184 | 186 | assertEscape(input, escapingScheme, expected, unescapeExpected); |
185 | 187 | } |
@@ -294,49 +296,39 @@ static Stream<Arguments> escapeNameUtf8TestCases() { |
294 | 296 | "http.status:sum")); |
295 | 297 | } |
296 | 298 |
|
297 | | - @Test |
298 | | - public void testValueUnescapeErrors() { |
299 | | - // empty string |
300 | | - assertThat(unescapeName("", EscapingScheme.VALUE_ENCODING_ESCAPING)).isEmpty(); |
301 | | - |
302 | | - // basic case, no error |
303 | | - assertThat(unescapeName("U__no:unescapingrequired", EscapingScheme.VALUE_ENCODING_ESCAPING)) |
304 | | - .isEqualTo("no:unescapingrequired"); |
305 | | - |
306 | | - // capitals ok, no error |
307 | | - assertThat(unescapeName("U__capitals_2E_ok", EscapingScheme.VALUE_ENCODING_ESCAPING)) |
308 | | - .isEqualTo("capitals.ok"); |
309 | | - |
310 | | - // underscores, no error |
311 | | - assertThat(unescapeName("U__underscores__doubled__", EscapingScheme.VALUE_ENCODING_ESCAPING)) |
312 | | - .isEqualTo("underscores_doubled_"); |
313 | | - |
314 | | - // invalid single underscore |
315 | | - assertThat(unescapeName("U__underscores_doubled_", EscapingScheme.VALUE_ENCODING_ESCAPING)) |
316 | | - .isEqualTo("U__underscores_doubled_"); |
317 | | - |
318 | | - // invalid single underscore, 2 |
319 | | - assertThat(unescapeName("U__underscores__doubled_", EscapingScheme.VALUE_ENCODING_ESCAPING)) |
320 | | - .isEqualTo("U__underscores__doubled_"); |
321 | | - |
322 | | - // giant fake UTF-8 code |
323 | | - assertThat( |
324 | | - unescapeName( |
325 | | - "U__my__hack_2e_attempt_872348732fabdabbab_", |
326 | | - EscapingScheme.VALUE_ENCODING_ESCAPING)) |
327 | | - .isEqualTo("U__my__hack_2e_attempt_872348732fabdabbab_"); |
328 | | - |
329 | | - // trailing UTF-8 |
330 | | - assertThat(unescapeName("U__my__hack_2e", EscapingScheme.VALUE_ENCODING_ESCAPING)) |
331 | | - .isEqualTo("U__my__hack_2e"); |
332 | | - |
333 | | - // invalid UTF-8 value |
334 | | - assertThat(unescapeName("U__bad__utf_2eg_", EscapingScheme.VALUE_ENCODING_ESCAPING)) |
335 | | - .isEqualTo("U__bad__utf_2eg_"); |
336 | | - |
337 | | - // surrogate UTF-8 value |
338 | | - assertThat(unescapeName("U__bad__utf_D900_", EscapingScheme.VALUE_ENCODING_ESCAPING)) |
339 | | - .isEqualTo("U__bad__utf_D900_"); |
| 299 | + @ParameterizedTest |
| 300 | + @CsvSource( |
| 301 | + value = { |
| 302 | + // empty string |
| 303 | + ",", |
| 304 | + // basic case, no error |
| 305 | + "U__no:unescapingrequired,no:unescapingrequired", |
| 306 | + // capitals ok, no error |
| 307 | + "U__capitals_2E_ok,capitals.ok", |
| 308 | + // underscores, no error |
| 309 | + "U__underscores__doubled__,underscores_doubled_", |
| 310 | + // invalid single underscore |
| 311 | + "U__underscores_doubled_,U__underscores_doubled_", |
| 312 | + // invalid single underscore, 2 |
| 313 | + "U__underscores__doubled_,U__underscores__doubled_", |
| 314 | + // giant fake UTF-8 code |
| 315 | + "U__my__hack_2e_attempt_872348732fabdabbab_,U__my__hack_2e_attempt_872348732fabdabbab_", |
| 316 | + // trailing UTF-8 |
| 317 | + "U__my__hack_2e,U__my__hack_2e", |
| 318 | + // invalid UTF-8 value |
| 319 | + "U__bad__utf_2eg_,U__bad__utf_2eg_", |
| 320 | + // surrogate UTF-8 value |
| 321 | + "U__bad__utf_D900_,U__bad__utf_D900_", |
| 322 | + }) |
| 323 | + public void testValueUnescapeErrors(String escapedName, String expectedUnescapedName) { |
| 324 | + if (escapedName == null) { |
| 325 | + escapedName = ""; |
| 326 | + } |
| 327 | + if (expectedUnescapedName == null) { |
| 328 | + expectedUnescapedName = ""; |
| 329 | + } |
| 330 | + assertThat(unescapeName(escapedName, EscapingScheme.VALUE_ENCODING_ESCAPING)) |
| 331 | + .isEqualTo(expectedUnescapedName); |
340 | 332 | } |
341 | 333 |
|
342 | 334 | @Test |
|
0 commit comments