From 4282a541d0fdca94ae541c273455433ccaa6686b Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Wed, 4 Nov 2026 20:16:19 +0900 Subject: [PATCH] =?UTF-8?q?fix(forms):=20=ED=95=84=EB=93=9C=20code=20?= =?UTF-8?q?=EB=AC=B8=EA=B5=AC=EB=A5=BC=20=ED=91=9C=EC=9D=98=20=EC=9E=90?= =?UTF-8?q?=EA=B8=B0=20=ED=82=A4=EB=A1=9C=EB=A7=8C=20=EC=B0=BE=EB=8A=94?= =?UTF-8?q?=EB=8B=A4=20(1103/08-03)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제 validationMessage가 VALIDATION_COPY[code]로 찾았다. Object.freeze({...})는 Object.prototype을 물려받으므로 constructor·toString·hasOwnProperty· __proto__는 undefined가 아니라 함수·객체가 되고 ?? 대체가 걸리지 않았다. 그 값이 문구 키로 넘어가 "요청한 문구를 표시할 수 없습니다."가 나왔다. 고른 방법 같은 영역의 다른 표(route-codecs.ts, backend-envelope.ts)처럼 Object.hasOwn으로 자기 키만 본다. 표를 Object.create(null)로 바꾸는 대안은 타입 선언과 다른 표의 관용이 갈려 버렸다. 위험·한계 짝 백엔드는 대문자 code만 보내므로 짝 구성의 화면 결과는 바뀌지 않는다. 검증 - RED: 내장 이름 4개 행이 수정 전 실패, SOME_FUTURE_CODE 행은 통과. - form-foundation.test.tsx 28건 통과. eslint, tsc(app) 통과. Refs: docs/reviews/2026-11-03-maturity-review/08-presentation.md 08-03 --- src/presentation/forms/form-contracts.ts | 7 +++++-- tests/component/form-foundation.test.tsx | 14 +++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/presentation/forms/form-contracts.ts b/src/presentation/forms/form-contracts.ts index d424b6e3..eb9622bd 100644 --- a/src/presentation/forms/form-contracts.ts +++ b/src/presentation/forms/form-contracts.ts @@ -71,9 +71,12 @@ export function validationMessage( code: string, message: MessageResolver = defaultMessage, ): string { + // 1103/08-03. Own keys only: a server code such as `constructor` must not + // resolve to a name the frozen table inherits from Object.prototype. return message( - VALIDATION_COPY[code as keyof typeof VALIDATION_COPY] ?? - "form.validation.unknown", + Object.hasOwn(VALIDATION_COPY, code) + ? VALIDATION_COPY[code as keyof typeof VALIDATION_COPY] + : "form.validation.unknown", ); } diff --git a/tests/component/form-foundation.test.tsx b/tests/component/form-foundation.test.tsx index dc0e893e..74b427bd 100644 --- a/tests/component/form-foundation.test.tsx +++ b/tests/component/form-foundation.test.tsx @@ -596,11 +596,15 @@ describe("paired backend field codes", () => { }, ); - it("keeps the default copy for a code it does not know", () => { - expect(validationMessage("SOME_FUTURE_CODE")).toBe( - formatMessage("ko-KR", "form.validation.unknown"), - ); - }); + it.each(["SOME_FUTURE_CODE", "constructor", "toString", "__proto__", "hasOwnProperty"])( + "keeps the default copy for a code it does not know (%s)", + (code) => { + // 1103/08-03. Names inherited from Object.prototype are unknown codes too. + expect(validationMessage(code)).toBe( + formatMessage("ko-KR", "form.validation.unknown"), + ); + }, + ); }); describe("dirty navigation guard", () => {