Skip to content

Conversation

simonLeary42
Copy link
Collaborator

@simonLeary42 simonLeary42 commented Sep 29, 2025

  • create new utility \jsonEncode which always enables the flags JSON_THROW_ON_ERROR, JSON_UNESCAPED_SLASHES
  • update phpopenldaper to also use the JSON_THROW_ON_ERROR flag
  • replace uses of json_encode with jsonEncode
  • document new convention that jsonEncode must be used instead of json_encode
  • add pre-commit hook to enforce new convention
  • add pre-commit hook to enforce another similar convention
  • extend UnityHTTPD::getUploadedFileContents to encode the file with the specified encoding (default utf8) and do UnityHTTPD::badRequest upon encoding error
  • extend UnityHTTPD::errorLog to handle the situtation where $data cannot be JSON encoded, so that the other information can still be logged

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new utility function jsonEncode() to standardize JSON encoding across the codebase with consistent error handling and formatting. The changes enforce the use of JSON_THROW_ON_ERROR and JSON_UNESCAPED_SLASHES flags by default, replace all instances of json_encode() with the new utility, and add enforcement mechanisms to prevent future use of the native function.

  • Introduces jsonEncode() utility function with standardized flags
  • Replaces all json_encode() calls with jsonEncode()
  • Enhances file upload handling with encoding conversion support
  • Improves error logging to handle JSON encoding failures gracefully

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
resources/lib/utils.php Adds new jsonEncode() utility function and updates existing usage
resources/lib/UnityHTTPD.php Updates error logging and file upload methods to use new utility and handle encoding
resources/lib/UnityWebhook.php Replaces json_encode() with \jsonEncode()
resources/lib/UnityLDAP.php Replaces json_encode() with \jsonEncode()
webroot/api/notices/index.php Replaces json_encode() with jsonEncode()
test/assert-no-json_encode.bash Adds test script to enforce jsonEncode() usage
test/assert-no-assert.bash Adds test script to enforce ensure() usage
.pre-commit-config.yaml Adds pre-commit hooks for enforcement
CONTRIBUTING.md Updates guidelines to document new requirements

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@simonLeary42 simonLeary42 changed the title throw JSON errors, decode files, handle bad data in errorLog throw JSON errors, ensure file encoding, handle bad data in errorLog Sep 29, 2025
@simonLeary42 simonLeary42 force-pushed the robust branch 3 times, most recently from a4d00f1 to f52e4bc Compare September 29, 2025 23:12
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 15 out of 16 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@simonLeary42 simonLeary42 merged commit e8aac02 into main Sep 30, 2025
2 checks passed
@simonLeary42 simonLeary42 deleted the robust branch September 30, 2025 14:35
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.

2 participants