fix(forms): 필드 code 문구를 표의 자기 키로만 찾는다 (1103/08-03)

문제
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
This commit is contained in:
DongHyeonka
2026-11-04 20:16:19 +09:00
parent 0aada28b91
commit 4282a541d0
2 changed files with 14 additions and 7 deletions
+5 -2
View File
@@ -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",
);
}
+9 -5
View File
@@ -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", () => {