Add UTF-8 body content validation#89
Conversation
There was a problem hiding this comment.
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
ContentValidatorinterface +BodyNotUtf8ContentValidatorimplementation usingpreg_match()UTF-8 check. - Extend
SecurityTxtValidatorto run content validators and require raw$contentsduring validation. - Add tests and a new
SecurityTxtContentNotUtf8violation 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.
081c987 to
0f69bef
Compare
There was a problem hiding this comment.
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
ContentValidatorinterface andBodyNotUtf8ContentValidatorusingpreg_match('//u', ...)to detect invalid UTF-8. - Add new spec violation
SecurityTxtContentNotUtf8and wire content validation intoSecurityTxtValidator+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.
0f69bef to
0e10c2a
Compare
There was a problem hiding this comment.
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
SecurityTxtContentNotUtf8violation 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.
0e10c2a to
9ac1afb
Compare
There was a problem hiding this comment.
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
SecurityTxtContentNotUtf8spec violation for invalid body encoding. - Short-circuit
SecurityTxtParser::parseString()when body content is not valid UTF‑8 (usingpreg_match()with theuflag). - 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.
9ac1afb to
760cb18
Compare
There was a problem hiding this comment.
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 inSecurityTxtParser::parseString()that short-circuits with aSecurityTxtContentNotUtf8file error. - Introduce a new
SecurityTxtContentNotUtf8violation 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.
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.
760cb18 to
115a4c7
Compare
There was a problem hiding this comment.
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 usingpreg_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.
The content validation has to run before any other validation to reject non-UTF-8 early enough.
preg_match()'suflag is used instead ofmb_check_encoding()to avoid adding thembstringextension as a dependency.