Skip to content

Fix comment-json@5 CommentArray detection in project config sanitization - #509

Merged
jhuleatt merged 1 commit into
masterfrom
fix/comment-json-array-check
Nov 19, 2026
Merged

jhuleatt merged 1 commit into
masterfrom
fix/comment-json-array-check

Conversation

@jhuleatt

Copy link
Copy Markdown
Contributor

Summary

  • Replace obj.constructor === Array with Array.isArray(obj) in Project.lowercaseMapKeys and Project.arraysToMaps, and arr[0].constructor === String with typeof arr[0] === "string".
  • comment-json@5 parses JSON arrays into CommentArray subclasses (arr.constructor !== Array), which previously caused sanitizeForStorage to skip converting platforms and related arrays into Firestore boolean maps ({ [key]: true }), breaking downstream frontend static generation expecting object maps.

Testing

  • Built functions cleanly (npm --prefix=functions run build).
  • Verified Project.prototype.sanitizeForStorage converts cjson.parse('{"platforms":["PHP","Admin"],"related":["a/b"]}', null, true) to { platforms: { php: true, admin: true }, related: { 'a/b': true } }.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors array type checks in functions/src/project.ts to use Array.isArray() and simplifies string type checking. A review comment suggests ensuring all elements in the array are strings using Array.prototype.every() to prevent potential runtime errors when handling mixed-type arrays.

Comment thread functions/src/project.ts
arr.length > 0 &&
arr[0].constructor === String
) {
if (Array.isArray(arr) && arr.length > 0 && typeof arr[0] === "string") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current check only verifies that the first element of the array is a string (typeof arr[0] === "string"). If the array contains mixed types (e.g., ["web", 123]), calling item.toLowerCase() inside the loop will throw a runtime TypeError. To prevent this and fully adhere to the comment ('Only sanitize if it's a non-empty array of strings'), we should ensure that all elements in the array are strings using Array.prototype.every().

Suggested change
if (Array.isArray(arr) && arr.length > 0 && typeof arr[0] === "string") {
if (Array.isArray(arr) && arr.length > 0 && arr.every(item => typeof item === "string")) {

@jhuleatt
jhuleatt merged commit 81c0939 into master Nov 19, 2026
13 checks passed
@jhuleatt
jhuleatt deleted the fix/comment-json-array-check branch November 19, 2026 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant