(t *testing.T)
| 524 | } |
| 525 | |
| 526 | func TestStringToGoStringValue(t *testing.T) { |
| 527 | testCases := []struct { |
| 528 | input string |
| 529 | expected string |
| 530 | message string |
| 531 | }{ |
| 532 | { |
| 533 | input: ``, |
| 534 | expected: `""`, |
| 535 | message: "blank string should be converted to empty Go string literal", |
| 536 | }, |
| 537 | { |
| 538 | input: `application/json`, |
| 539 | expected: `"application/json"`, |
| 540 | message: "typical string should be returned as-is", |
| 541 | }, |
| 542 | { |
| 543 | input: `application/json; foo="bar"`, |
| 544 | expected: `"application/json; foo=\"bar\""`, |
| 545 | message: "string with quotes should include escape characters", |
| 546 | }, |
| 547 | { |
| 548 | // The previous implementation only escaped `"`, so a backslash |
| 549 | // before a quote (`\"`) escaped the escaping and let untrusted |
| 550 | // spec text break out of the generated string literal. |
| 551 | input: `a\"; var Evil = 1; var _ = "`, |
| 552 | expected: `"a\\\"; var Evil = 1; var _ = \""`, |
| 553 | message: "backslashes must be escaped so a quote cannot break out of the literal", |
| 554 | }, |
| 555 | { |
| 556 | input: "line1\nline2", |
| 557 | expected: `"line1\nline2"`, |
| 558 | message: "newlines must be escaped so they cannot terminate the literal", |
| 559 | }, |
| 560 | } |
| 561 | for _, testCase := range testCases { |
| 562 | t.Run(testCase.message, func(t *testing.T) { |
| 563 | result := StringToGoString(testCase.input) |
| 564 | assert.EqualValues(t, testCase.expected, result, testCase.message) |
| 565 | }) |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | func TestStringToGoComment(t *testing.T) { |
| 570 | testCases := []struct { |
nothing calls this directly
no test coverage detected