Skip to content

Add regression test for enum values containing backslashes#2454

Merged
mromaszewicz merged 1 commit into
mainfrom
fix/issue-2180
Jul 12, 2026
Merged

Add regression test for enum values containing backslashes#2454
mromaszewicz merged 1 commit into
mainfrom
fix/issue-2180

Conversation

@mromaszewicz

Copy link
Copy Markdown
Member

Closes: #2180

The reported miscompilation — a string enum value like N\A emitted verbatim into a double-quoted Go literal — was already fixed by #2433, which routes string enum constants through strconv.Quote. That change shipped without an end-to-end test for this scenario, so pin it with a test generating from the issue's schema and asserting the escaped constant and formattable output.

Closes: #2180

The reported miscompilation — a string enum value like N\A emitted
verbatim into a double-quoted Go literal — was already fixed by #2433,
which routes string enum constants through strconv.Quote. That change
shipped without an end-to-end test for this scenario, so pin it with a
test generating from the issue's schema and asserting the escaped
constant and formattable output.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mromaszewicz
mromaszewicz requested a review from a team as a code owner July 12, 2026 18:06
@mromaszewicz mromaszewicz added the bug Something isn't working label Jul 12, 2026
@greptile-apps

greptile-apps Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a regression test for the backslash-in-enum-value miscompilation fixed in #2433, confirming that strconv.Quote is correctly applied so a value like N\A is emitted as a valid \"N\\A\" Go literal and that the generated output passes go/format.

  • A new TestEnumValueEscaping function is added to pkg/codegen/codegen_test.go, with an inline OpenAPI spec defining a string enum containing N\A, asserting the escaped constant is present, and asserting the output is gofmt-clean.
  • The test is placed in pkg/codegen/codegen_test.go rather than in the existing internal/test/schemas/enums category leaf, which is where the project's test-placement rules direct enum-escaping scenarios.

Confidence Score: 4/5

Safe to merge — the test correctly exercises the fix and cannot break anything in production code.

The only change is an additive test that passes today. The sole concern is organizational: the test lives in codegen_test.go instead of the internal/test/schemas/enums leaf, which means no committed golden file is produced and the connection to the project's feature-category test tree is lost.

No files require special attention beyond the test placement question in pkg/codegen/codegen_test.go.

Important Files Changed

Filename Overview
pkg/codegen/codegen_test.go Adds TestEnumValueEscaping, which correctly verifies that a backslash-containing enum value is emitted as a properly escaped Go literal and that the output is go/format-clean. Functionally sound, but placed in codegen_test.go instead of the canonical internal/test/schemas/enums leaf where it would also produce a committed golden file.
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
pkg/codegen/codegen_test.go:584-626
**Test belongs in `internal/test/schemas/enums`, not `codegen_test.go`**

Per the project's test placement rules, enum-escaping scenarios belong in `internal/test/schemas/enums`. The existing leaf already tests illegal identifier generation from pathological enum string values; a backslash-containing value is the same construct with one more variant. The fix is straightforward: add `"N\\A"` to the `Bar` enum in `internal/test/schemas/enums/spec.yaml` (that spec has a path using `Bar`, so `SkipPrune` is not needed), add an assertion in `enums_test.go`, and regenerate `enums.gen.go`. Landing the change in the generated golden file gives a committed proof that `strconv.Quote` is in the output and gives CI a diff-check that will catch any future regression at the template level.

Reviews (1): Last reviewed commit: "Add regression test for enum values cont..." | Re-trigger Greptile

@mromaszewicz
mromaszewicz merged commit 05eb4a7 into main Jul 12, 2026
29 checks passed
@mromaszewicz
mromaszewicz deleted the fix/issue-2180 branch July 12, 2026 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enum values with backslash (escape character) produce invalid client code

1 participant