Skip to content

Add UTF-8 body content validation#89

Merged
spaze merged 1 commit into
mainfrom
spaze/utf-8-body-validation
Apr 11, 2026
Merged

Add UTF-8 body content validation#89
spaze merged 1 commit into
mainfrom
spaze/utf-8-body-validation

Conversation

@spaze

@spaze spaze commented Apr 11, 2026

Copy link
Copy Markdown
Owner

The content validation has to run before any other validation to reject non-UTF-8 early enough. preg_match()'s u flag is used instead of mb_check_encoding() to avoid adding the mbstring extension as a dependency.

@spaze spaze self-assigned this Apr 11, 2026
Copilot AI review requested due to automatic review settings April 11, 2026 00:24

Copilot AI 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.

Pull request overview

Adds file-body UTF-8 validation as part of overall security.txt file-level validation, introducing a new ContentValidator chain that operates on raw bytes (pre-parse) rather than the parsed SecurityTxt object.

Changes:

  • Add ContentValidator interface + BodyNotUtf8ContentValidator implementation using preg_match() UTF-8 check.
  • Extend SecurityTxtValidator to run content validators and require raw $contents during validation.
  • Add tests and a new SecurityTxtContentNotUtf8 violation to surface non-UTF-8 input.

Reviewed changes

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

Show a summary per file
File Description
tests/Validator/SecurityTxtValidatorTest.phpt Adds a validator-level test for non-UTF-8 contents and updates helpers to pass contents through.
tests/Parser/SecurityTxtParserTest.phpt Adds a parser-level test ensuring non-UTF-8 input becomes a file error.
src/Violations/SecurityTxtContentNotUtf8.php Introduces a new spec violation for invalid UTF-8 file contents.
src/Validator/Validators/ContentValidator.php Adds a new validator interface for raw content validation.
src/Validator/Validators/BodyNotUtf8ContentValidator.php Implements UTF-8 validation via preg_match('//u', ...).
src/Validator/SecurityTxtValidator.php Adds content validators and changes validate() signature to accept raw $contents.
src/Parser/SecurityTxtParser.php Passes $contents through to the validator.
CLAUDE.md Updates documentation to mention content encoding validation and ContentValidator.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Validator/Validators/BodyNotUtf8ContentValidator.php Outdated
Comment thread src/Validator/SecurityTxtValidator.php Outdated
@spaze
spaze force-pushed the spaze/utf-8-body-validation branch from 081c987 to 0f69bef Compare April 11, 2026 00:53
@spaze
spaze requested a review from Copilot April 11, 2026 00:53

Copilot AI 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.

Pull request overview

Adds file-body UTF-8 validation to the parsing/validation pipeline by introducing content-level validators that operate on the raw bytes (separate from field validators operating on SecurityTxt).

Changes:

  • Introduce ContentValidator interface and BodyNotUtf8ContentValidator using preg_match('//u', ...) to detect invalid UTF-8.
  • Add new spec violation SecurityTxtContentNotUtf8 and wire content validation into SecurityTxtValidator + SecurityTxtParser.
  • Add/adjust tests to assert invalid UTF-8 is reported as a file-level error.

Reviewed changes

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

Show a summary per file
File Description
tests/Validator/SecurityTxtValidatorTest.phpt Adds validator-level test for invalid UTF-8; updates helper methods to pass contents through.
tests/Parser/SecurityTxtParserTest.phpt Adds parser-level test ensuring invalid UTF-8 becomes a file error.
src/Violations/SecurityTxtContentNotUtf8.php New violation class for non-UTF-8 content.
src/Validator/Validators/ContentValidator.php New interface for validators operating on raw contents bytes.
src/Validator/Validators/BodyNotUtf8ContentValidator.php Implements UTF-8 validity check via PCRE u modifier (with silenced warnings).
src/Validator/SecurityTxtValidator.php Extends validator to optionally validate raw contents via content validators.
src/Parser/SecurityTxtParser.php Passes raw contents into SecurityTxtValidator from parseString().
CLAUDE.md Updates documentation to mention content encoding validation + ContentValidator.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Parser/SecurityTxtParser.php Outdated
Comment thread tests/Validator/SecurityTxtValidatorTest.phpt Outdated
@spaze
spaze force-pushed the spaze/utf-8-body-validation branch from 0f69bef to 0e10c2a Compare April 11, 2026 03:12
@spaze
spaze requested a review from Copilot April 11, 2026 03:15

Copilot AI 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.

Pull request overview

Adds an early validation step to reject non‑UTF‑8 security.txt bodies during parsing, reporting a dedicated spec violation instead of proceeding with line parsing.

Changes:

  • Introduces a new SecurityTxtContentNotUtf8 violation type.
  • Adds a UTF‑8 validity check in SecurityTxtParser::parseString() that short-circuits parsing on failure.
  • Adds a parser test to ensure invalid UTF‑8 content is reported as a file-level error.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tests/Parser/SecurityTxtParserTest.phpt Adds coverage for invalid UTF‑8 input producing SecurityTxtContentNotUtf8.
src/Violations/SecurityTxtContentNotUtf8.php New spec violation for non‑UTF‑8 body content.
src/Validator/SecurityTxtValidator.php Adds a helper to build a SecurityTxtValidateResult for the UTF‑8 failure case.
src/Parser/SecurityTxtParser.php Adds the UTF‑8 validation short-circuit during parseString().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Parser/SecurityTxtParser.php
Comment thread src/Validator/SecurityTxtValidator.php Outdated
Comment thread src/Parser/SecurityTxtParser.php Outdated
@spaze
spaze force-pushed the spaze/utf-8-body-validation branch from 0e10c2a to 9ac1afb Compare April 11, 2026 03:29
@spaze
spaze requested a review from Copilot April 11, 2026 03:29

Copilot AI 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.

Pull request overview

Adds early UTF-8 validation for parsed security.txt body content so non‑UTF‑8 inputs are rejected before other parsing/validation occurs, without introducing an mbstring dependency.

Changes:

  • Add a new SecurityTxtContentNotUtf8 spec violation for invalid body encoding.
  • Short-circuit SecurityTxtParser::parseString() when body content is not valid UTF‑8 (using preg_match() with the u flag).
  • Add a parser test asserting invalid UTF‑8 input yields the new file-level error.

Reviewed changes

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

File Description
tests/Parser/SecurityTxtParserTest.phpt Adds test coverage for invalid UTF‑8 body handling in parseString().
src/Violations/SecurityTxtContentNotUtf8.php Introduces a new violation type representing non‑UTF‑8 body content.
src/Parser/SecurityTxtParser.php Implements early UTF‑8 detection + short-circuit returning SecurityTxtContentNotUtf8.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Parser/SecurityTxtParser.php
@spaze
spaze force-pushed the spaze/utf-8-body-validation branch from 9ac1afb to 760cb18 Compare April 11, 2026 03:38
@spaze
spaze requested a review from Copilot April 11, 2026 03:38

Copilot AI 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.

Pull request overview

Adds early UTF-8 validation of the raw security.txt body during parsing so non‑UTF‑8 content is rejected before any line/field parsing can occur (avoiding downstream issues like invalid bytes leaking into violations/serialization).

Changes:

  • Add an early preg_match('//u', $contents) UTF‑8 check in SecurityTxtParser::parseString() that short-circuits with a SecurityTxtContentNotUtf8 file error.
  • Introduce a new SecurityTxtContentNotUtf8 violation type.
  • Add a parser test covering non‑UTF‑8 input.

Reviewed changes

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

File Description
src/Parser/SecurityTxtParser.php Short-circuits parsing on invalid UTF‑8 and returns a SecurityTxtValidateResult containing SecurityTxtContentNotUtf8.
src/Violations/SecurityTxtContentNotUtf8.php New spec violation representing non‑UTF‑8 body content.
tests/Parser/SecurityTxtParserTest.phpt Adds a test expecting SecurityTxtContentNotUtf8 when parsing invalid UTF‑8 bytes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/Parser/SecurityTxtParserTest.phpt
The content validation has to run before any other validation to reject non-UTF-8 early enough. preg_match()'s u flag is used instead of mb_check_encoding() to avoid adding the mbstring extension as a dependency.
@spaze
spaze force-pushed the spaze/utf-8-body-validation branch from 760cb18 to 115a4c7 Compare April 11, 2026 13:31
@spaze
spaze requested a review from Copilot April 11, 2026 13:31

Copilot AI 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.

Pull request overview

Adds an early UTF-8 validation step to the parsing pipeline so that non‑UTF‑8 security.txt contents are rejected before any line parsing/field validation occurs, without introducing an mbstring dependency.

Changes:

  • Short-circuit SecurityTxtParser::parseString() on invalid UTF‑8 using preg_match('//u', ...) and return a file-level violation.
  • Introduce a new spec violation type SecurityTxtContentNotUtf8.
  • Add a parser test ensuring invalid UTF‑8 yields exactly one file error and no line-level errors/warnings.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/Parser/SecurityTxtParser.php Adds early UTF‑8 validation and returns SecurityTxtContentNotUtf8 before any line processing.
src/Violations/SecurityTxtContentNotUtf8.php New violation representing non‑UTF‑8 body content.
tests/Parser/SecurityTxtParserTest.phpt Adds regression test ensuring early rejection produces only a file-level error.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@spaze
spaze merged commit 96e7726 into main Apr 11, 2026
10 checks passed
@spaze
spaze deleted the spaze/utf-8-body-validation branch April 11, 2026 13:40
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