Skip to content

Conversation

@Meldiron
Copy link
Contributor

@Meldiron Meldiron commented Aug 19, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Stricter domain validation: rejects trailing/leading dots, consecutive dots, improper hyphen placement, whitespace, and dot-only/empty values to prevent invalid domains.
  • Tests

    • Expanded negative test coverage for many malformed domain cases and added non-string input checks to ensure consistent validation.
  • Chores

    • Loosened dev dependency version constraints to allow broader 1.x releases for tooling.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 19, 2025

Walkthrough

Domain validator now uses FILTER_VALIDATE_DOMAIN with FILTER_FLAG_HOSTNAME and explicitly rejects values ending with a dot or hyphen. Tests were expanded with many negative cases for malformed domains. Composer dev constraints for two tools were loosened. No public signatures changed.

Changes

Cohort / File(s) Summary of changes
Validator logic update
src/Http/Validator/Domain.php
Switched to FILTER_VALIDATE_DOMAIN with FILTER_FLAG_HOSTNAME; added explicit rejection for values ending with . or -; preserved existing empty/non-string guards and final success path.
Test coverage expansion
tests/Validator/DomainTest.php
Added many negative test cases for malformed domains (trailing/leading/double dots, hyphen misuse, whitespace, single/double dot, empty); added assertion for non-string input; one duplicate test line noted.
Dev dependency constraints
composer.json
Loosened dev version constraints: laravel/pint from ^1.21.*, phpstan/phpstan from ^1.101.*; no runtime code changes.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Caller
    participant Domain as Domain::isValid
    participant PHPFilter as filter_var

    Caller->>Domain: isValid(value)
    alt Guard: empty or non-string
        Domain-->>Caller: false
    else Guard: trailing dot or hyphen
        Note right of Domain: New checks: str_ends_with(value, ".") or str_ends_with(value, "-")
        Domain-->>Caller: false
    else Validate hostname
        Domain->>PHPFilter: filter_var(value, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)
        PHPFilter-->>Domain: (bool)
        alt Valid
            Domain-->>Caller: true
        else Invalid
            Domain-->>Caller: false
        end
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my ears at dots that stray,
I thump my foot at hyphens' way—
No doubles, spaces, leading blight,
I sift the names from wrong to right.
A rabbit's nod, the hosts are neat. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-improve-

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/Validator/DomainTest.php (1)

16-47: Update expectations for underscore-containing hostnames; this causes the PHPUnit failure

With FILTER_VALIDATE_DOMAIN + FILTER_FLAG_HOSTNAME, host labels must be alphanumeric plus hyphens; underscores are invalid. The current positive assertions for domains with underscores now fail (see pipeline error pointing at Line 22). Adjust those expectations (and consider removing duplicated 'example.org' as a minor cleanup).

Apply this diff to align tests with the new validator semantics and remove a duplicate:

         $this->assertEquals(true, $this->domain->isValid('subdomain.example-app.com'));
-        $this->assertEquals(true, $this->domain->isValid('subdomain.example_app.com'));
+        $this->assertEquals(false, $this->domain->isValid('subdomain.example_app.com'));
         $this->assertEquals(true, $this->domain->isValid('subdomain-new.example.com'));
-        $this->assertEquals(true, $this->domain->isValid('subdomain_new.example.com'));
+        $this->assertEquals(false, $this->domain->isValid('subdomain_new.example.com'));
         $this->assertEquals(true, $this->domain->isValid('localhost'));
         $this->assertEquals(true, $this->domain->isValid('example.io'));
         $this->assertEquals(true, $this->domain->isValid('example.org'));
-        $this->assertEquals(true, $this->domain->isValid('example.org'));

Notes:

  • Keeping 'localhost' as valid is consistent with FILTER_FLAG_HOSTNAME behavior in recent PHP versions. If your minimum PHP version treats it differently, we can revisit.
🧹 Nitpick comments (1)
tests/Validator/DomainTest.php (1)

30-40: Great negative coverage; remove duplicate assertion and keep cases concise

  • Duplicate assertion for the same input appears twice ('.api.appwrite.io'). Remove one to avoid redundancy.

Apply this diff to remove the duplicate on Line 32:

-        $this->assertEquals(false, $this->domain->isValid('.api.appwrite.io'));
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e432558 and 99ce84d.

📒 Files selected for processing (2)
  • src/Http/Validator/Domain.php (1 hunks)
  • tests/Validator/DomainTest.php (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/Validator/DomainTest.php (1)
src/Http/Validator/Domain.php (1)
  • isValid (38-57)
🪛 GitHub Actions: Tests
tests/Validator/DomainTest.php

[error] 22-22: PHPUnit failure: DomainTest::testIsValid - Failed asserting that false matches expected true. Step: docker compose exec fpm vendor/bin/phpunit --configuration phpunit.xml

🪛 GitHub Actions: Linter
src/Http/Validator/Domain.php

[error] 1-1: Pint lint failed (vendor/bin/pint --test). PSR-12 violation detected: 'single_space_around_construct' in src/Http/Validator/Domain.php.

🔇 Additional comments (1)
src/Http/Validator/Domain.php (1)

48-50: Switch to FILTER_VALIDATE_DOMAIN with FILTER_FLAG_HOSTNAME looks good

This tightens validation to hostname semantics, aligning with RFC-compliant host labels (disallowing underscores, etc.). This change is consistent with the new negative tests you added.

@Meldiron Meldiron merged commit 8bbe56a into master Aug 19, 2025
4 of 5 checks passed
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
composer.json (1)

39-41: Looser dev constraints are fine; consider keeping a known floor to avoid older 1.x installs

Composer will typically resolve to the latest 1.x, but "1.*" also permits early 1.0 releases when a lock exists or mirrors lag, which may lack features you rely on. If the intent is to broaden to 1.x while preserving the previous minimums, consider adding an explicit lower bound.

Apply this diff to keep the broadened range but retain prior minimums:

-        "phpbench/phpbench": "^1.2",
-        "laravel/pint": "1.*",
-        "phpstan/phpstan": "1.*"
+        "phpbench/phpbench": "^1.2",
+        "laravel/pint": ">=1.2 <2.0",
+        "phpstan/phpstan": ">=1.10 <2.0"
tests/Validator/DomainTest.php (2)

30-40: Strong negative coverage; remove the duplicate leading-dot case or replace it

Great set of malformed examples. Lines 31 and 32 duplicate the same assertion for '.api.appwrite.io'. Remove the duplicate or replace it with another common invalid form to increase coverage (e.g., a scheme-prefixed string).

Replace the duplicate with a scheme-prefixed case:

-        $this->assertEquals(false, $this->domain->isValid('.api.appwrite.io'));
+        $this->assertEquals(false, $this->domain->isValid('http://appwrite.io'));

22-22: Optional: prefer assertTrue/assertFalse and/or a data provider for readability

Using assertFalse/assertTrue improves readability and failure messages. With many cases, a data provider or iterating over arrays of inputs would make this test easier to maintain. Not blocking.

Also applies to: 24-24, 30-40

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 99ce84d and 8c3469c.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • composer.json (1 hunks)
  • src/Http/Validator/Domain.php (1 hunks)
  • tests/Validator/DomainTest.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Http/Validator/Domain.php
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/Validator/DomainTest.php (1)
src/Http/Validator/Domain.php (1)
  • isValid (38-57)
🔇 Additional comments (1)
tests/Validator/DomainTest.php (1)

22-22: Good catch: underscore-containing labels marked invalid

Underscores are not permitted in hostnames per the LDH rule; aligning the tests with the stricter validator is correct.

Also applies to: 24-24

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.

3 participants